Registriert seit: 24. Dez 2002
Ort: Hamburg-Harburg
3.551 Beiträge
|
Re: String von ; Trennen (über TStringList)
12. Mai 2005, 09:59
Delphi-Quellcode:
function NumTok(const Str: string; const Sep: Char): Integer;
var
I: Integer;
LastWasSep: Boolean;
begin
Result := 0;
if Str <> '' then
begin
LastWasSep := True;
for I := 1 to Length(Str) do
begin
if (Str[I] <> Sep) and (LastWasSep) then
Inc(Result);
LastWasSep := Str[I] = Sep;
end;
end;
end;
function GetTok(const Str: string; const Idx: Integer; const Sep: Char): string;
var
I, TokCount, ResIdx: Integer;
LastWasSep: Boolean;
begin
Result := '';
if (Str <> '') and (Idx > 0) then
begin
Result := Str;
TokCount := 0;
ResIdx := 0;
LastWasSep := True;
for I := 1 to Length(Str) do
begin
if (Str[I] <> Sep) and (LastWasSep) then
Inc(TokCount);
if (Str[I] <> Sep) and (TokCount = Idx) then
begin
Inc(ResIdx);
Result[ResIdx] := Str[I];
end;
LastWasSep := Str[I] = Sep;
end;
SetLength(Result, ResIdx);
end;
end;
...
Delphi-Quellcode:
for I := 1 to NumTok(DeinString, ';') do
ShowMessage(Format('%d: %s', [I, GetTok(DeinString, I, ';')]));
MfG
Mario MSN: cyanide@ccode.de
|
|
Zitat
|