Delphi memo lines in one line

user2997342 picture user2997342 · May 4, 2014 · Viewed 19.1k times · Source

In a TMemo field I have 3 lines:

  1. line1
  2. line2
  3. line3

Is it posible to get all three lines as one string?

Example:

line1,line2,line3

Answer

Graymatter picture Graymatter · May 4, 2014

You can use the Lines.CommaText property for this. Do the following:

CommaString := Memo1.Lines.CommaText;

Its also useful to use the DelimitedText property if you want the text to make use of another separator character. You can do that by using something like this:

Memo1.Lines.Delimiter := '-';
Memo1.Lines.StrictDelimiter := True;
DashString := Memo1.Lines.DelimitedText;

This works both ways. You can assign a value to the CommaText or DelimiterText to set the lines. This is actually a of TStringList so it will work with TListBox, TMemo, TComboBox, etc. Basically anything that uses a string list internally.