Mega Code Archive

 
Categories / Delphi / VCL
 

How to separate words from a sentence into a stringlist with one line of code

//Example: a sentence must be broken up into words: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure BreakUp(const what, where: string; sl: TStrings); begin sl.Text:= StringReplace(what, where, #10, [rfReplaceAll, rfIgnoreCase]); end; procedure TForm1.Button1Click(Sender: TObject); begin BreakUp('This is a sentence.', ' ', Memo1.Lines); end; end.