...einzelne Wörter aus einem String extrahieren?
Autor: Thomas Stutz
function GetToken(aString, SepChar: string; TokenNum: Byte): string;
var
Token: string;
StrLen: Integer;
Num: Integer;
EndofToken: Integer;
begin
StrLen := Length(aString);
Num := 1;
EndofToken := StrLen;
while ((Num <= TokenNum) and (EndofToken <> 0)) do
begin
EndofToken := Pos(SepChar, aString);
if EndofToken <> 0 then
begin
Token := Copy(aString, 1, EndofToken - 1);
Delete(aString, 1, EndofToken);
Inc(Num);
end
else
Token := aString;
end;
if Num >= TokenNum then
Result := Token
else
Result := '';
end;
//Example/Beispiel:
GetToken('Word1 Word2 Word3', 2, ' ') = 'Word2'
GetToken('Word1/Word2/Word3', 2, '/') = 'Word2'
printed from
www.swissdelphicenter.ch
developers knowledge base