Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Trim dauert bis zu 5 minuten....Benötige schnelle Lösung (https://www.delphipraxis.net/142617-trim-dauert-bis-zu-5-minuten-benoetige-schnelle-loesung.html)

madas 3. Nov 2009 08:49

Re: Trim dauert bis zu 5 minuten....Benötige schnelle Lösung
 
Versuch es mal hiermit:

Delphi-Quellcode:
type
  TMyStringList = class(TStringList)
  private
    FCount: Integer;
  public
    constructor Create;

    function Add(const S: string): Integer; override;
    property TrueLineCount: Integer read FCount write FCount;
  end;

constructor TMyStringList.Create;
begin
  FCount := 0;
end;

function TMyStringList.Add(const S: string): Integer;
begin
  if (Trim(S) = EmptyStr) then
    Result := -1
  else
  begin
    Result := inherited Add(S);
    Inc(FCount);
  end;
end;
Braucht für ne 12MB Textdatei ca. 250 ms.

shmia 3. Nov 2009 15:48

Re: Trim dauert bis zu 5 minuten....Benötige schnelle Lösung
 
Um Festzustellen, ob eine Zeile leer ist reicht es aus, TrimRight() zu verwenden.
TrimRight() ist schneller als Trim(), da die Funktion weniger zu tun hat.

Noch schneller geht es mit folgender (ungetesteter) Funktion.
Anstatt die Leerzeichen, Tabs,... wirklich zu entfernen, wird nur geprüft,
ob ein String nur "Weißraum" enthält.
Delphi-Quellcode:
function IsWhiteSpace(const S: string): Boolean;
var
  I: Integer;
begin
  I := Length(S);
  while (I > 0) and (S[I] <= ' ') do Dec(I);
  Result := (I = 0);
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 20:29 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz