Jump to content
Registration disabled at the moment Read more... ×
Jeff Steinkamp

Split string on whitespace

Recommended Posts

Can someone point me in the right direction for splitting a string based on white space in a string.  In other words, the separator between elements could be 1 space, multiple spaces, or the tab character.

 

Thanks

Share this post


Link to post
1 hour ago, Jeff Steinkamp said:

In other words, the separator between elements could be 1 space, multiple spaces, or the tab character.

 

would be that?

 

procedure TForm1.Button1Click(Sender: TObject);
var
  LText  : string;
  LArrStr: TArray<string>;
begin
  LText := 'Hello World'#9' . .  Delphi in'#32'Action';
  // 2x spaces
  LArrStr := LText.Split(['  '  {, #9, #32}] { , TStringSplitOptions.ExcludeEmpty } );
  // Array with 2 items...  
  // 1x space
  LArrStr := LText.Split([' ', #9, #32] { , TStringSplitOptions.ExcludeEmpty } );
  // Array with 9 items...
  Memo1.Lines.AddStrings(LArrStr);
end;

 

Edited by programmerdelphi2k

Share this post


Link to post

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×