How to Split a Delphi String to Words / Tokens
Saturday June 28, 2008
in Delphi TIPS ::
GetNextToken returns the next token (substring) from a string, starting at an index and ending 1 character before the next occurrence of a Separator.
Split breaks a string containing designated separators into tokens and adds them to a string list.
AddToken joins 2 strings with a separator character between.
GetNextToken returns the next token (substring) from a string, starting at an index and ending 1 character before the next occurrence of a Separator.Split breaks a string containing designated separators into tokens and adds them to a string list.
AddToken joins 2 strings with a separator character between.
Read the full article to get the code to Split a Delphi String to Words / Tokens.
Related:


Comments
Your proposed functions certainly offer quite some flexibility, but I still think it’s worth mentioning that there is a fairly easy to use Tokenizer in the box already:
uses HTTPUtil;
procedure TForm22.Button1Click(Sender: TObject);
var
LTokenizer: IStringTokenizer;
begin
Memo1.Clear;
LTokenizer := StringTokenizer(Edit1.Text, ‘ ‘);
while LTokenizer.hasMoreTokens do
Memo1.Lines.Add(LTokenizer.nextToken);
end;