Zitat von
xaromz:
Hallo,
Zitat von
PeterPanino:
Wie würdest du es machen?
So:
Delphi-Quellcode:
type
TTrimDirection = set of (tdLeft, tdRight);
function PATrimChars(const S: String; CS: TSysCharSet; Direction: TTrimDirection): String;
var
i: Integer;
L, Left, Right: Integer;
begin
L := Length(S);
Left := 1;
if tdLeft in Direction then
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 dtRight in Direction then
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
Mhm, und was ist der Vorteil der Verwendung von Set gegenüber der Verwendung eines Char?