Thema: Delphi TrimChars

Einzelnen Beitrag anzeigen

xaromz

Registriert seit: 18. Mär 2005
1.682 Beiträge
 
Delphi 2006 Enterprise
 
#7

Re: TrimChars

  Alt 2. Jan 2007, 12:21
Hallo,

ich habe die Funktion etwas überarbeitet, sie kommt jetzt mit einem Copy aus, außerdem wird der QuellString als const übergeben. Das sollte die Performance etwas steigern.
Delphi-Quellcode:
function PATrimChars(const S: String; CS: TSysCharSet; T: Char): String;
var
  i: Integer;
  L, Left, Right: Integer;
begin
  L := Length(S);

  Left := 1;
  if T in ['L', 'B'] then // L = Left, B = Both
  begin
    for i := 1 to L do
    begin
      if not (S[i] in CS) then
      begin
        Left := i;
        Break;
      end;
    end;
  end;

  Right := L;
  if T in ['R', 'B'] then // R = Right, B = Both
  begin
    for i := L downto 1 do
    begin
      if not (S[i] in CS) then
      begin
        Right := i;
        Break;
      end;
    end;
  end;

  Result := Copy(S, Left, Right - Left + 1);
end;
Gruß
xaromz
I am a leaf on the wind - watch how I soar
  Mit Zitat antworten Zitat