Author: Jonas Bilinkevicius How to break strings into individual tokens (substrings) Answer: The following (simple) functions helped me handling substrings: function GetToken(aString, SepChar: string; TokenNum: Byte): string; {Parameters: aString: the complete string SepChar: a single character used as separator between the substrings TokenNum: the number of the substring you want result: the substring or an empty string if the are less then 'TokenNum' substrings} 1 var 2 Token: string; 3 StrLen: Byte; 4 TNum: Byte; 5 TEnd: Byte; 6 begin 7 StrLen := Length(aString); 8 TNum := 1; 9 TEnd := StrLen; 10 while ((TNum <= TokenNum) and (TEnd <> 0)) do 11 begin 12 TEnd := Pos(SepChar, aString); 13 if TEnd <> 0 then 14 begin 15 Token := Copy(aString, 1, TEnd - 1); 16 Delete(aString, 1, TEnd); 17 Inc(TNum); 18 end 19 else 20 begin 21 Token := aString; 22 end; 23 end; 24 if TNum >= TokenNum then 25 begin 26 GetToken1 := Token; 27 end 28 else 29 begin 30 GetToken1 := ''; 31 end; 32 end; 33 34 function NumToken(aString, SepChar: string): Byte; 35 36 {Parameters: 37 aString: the complete string 38 SepChar: a single character used as separator between the substrings 39 result: the number of substrings} 40 41 var 42 RChar: Char; 43 StrLen: Byte; 44 TNum: Byte; 45 TEnd: Byte; 46 begin 47 if SepChar = ' # ' then 48 begin 49 RChar := ' * ' 50 end 51 else 52 begin 53 RChar := ' # ' 54 end; 55 StrLen := Length(aString); 56 TNum := 0; 57 TEnd := StrLen; 58 while TEnd <> 0 do 59 begin 60 Inc(TNum); 61 TEnd := Pos(SepChar, aString); 62 if TEnd <> 0 then 63 begin 64 aString[TEnd] := RChar; 65 end; 66 end; 67 NumToken1 := TNum; 68 end;