2

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

Wouter van Nifterick
  • 23,603
  • 7
  • 78
  • 122
user2997342
  • 87
  • 2
  • 3
  • 8

3 Answers3

6

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.

Graymatter
  • 6,529
  • 2
  • 30
  • 50
  • Yes i now that, but i don't wan't comma at the end of the line. I want to combine (join) all three lines into one line. – user2997342 May 03 '14 at 22:29
  • You shouldn't get a comma at the end of the text. Have you tried Memo1.Text := Memo1.Lines.CommaText to put the three lines back into the same Memo? – Graymatter May 03 '14 at 22:34
0

maybe something like this suits your needs

d:=memo1.lines.count;
for i:=1 to d do
   memo1.lines[0]:=memo1.lines[0]+' '+memo1.lines[i];
for i:=1 to d do
   memo1.lines.Delete(1);
Rade
  • 1
-4

here is a 3 line function that do it.

function getOneLineMemo(memo:Tmemo):String;
var
  i:integer;
begin
  result := '';
  for i:=0 to memo1.lines.count do
     result := result + memo.lines[0];
end;
none
  • 4,669
  • 14
  • 62
  • 102