Jeff Steinkamp 1 Posted April 12, 2023 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
Tom F 85 Posted April 12, 2023 https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.StrUtils.SplitString Share this post Link to post
programmerdelphi2k 237 Posted April 12, 2023 (edited) 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 April 12, 2023 by programmerdelphi2k Share this post Link to post