Recent

Author Topic: Remove newlines (line break) from memo1.text?  (Read 11899 times)

seba22

  • Full Member
  • ***
  • Posts: 136
Remove newlines (line break) from memo1.text?
« on: December 27, 2010, 01:12:56 pm »
Welcome,

I have memo component and long string.

How can i grab that string into one line, one long string without line braks maked by enter.

If user copy text from website, it contain that line breaks

If user paste text
Code: [Select]
1
2
3
4

I need to get
Code: [Select]
1234
I was trying write it on my own, but i cant
Code: [Select]
procedure TForm1.Memo3Exit(Sender: TObject);
begin
  memo3.text:=trim(memo3.text);
end;

That was my idea.
It work ok, for enters at begining or end but not inside text
Code: [Select]
enter
text1
enter
text2
enter

after trim i got
Code: [Select]
text1
enter
text2

I should get : text1text2

Regards


typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Remove newlines (line break) from memo1.text?
« Reply #1 on: December 27, 2010, 01:26:08 pm »
Set WordWrap to False.

If you already did so, you could do:

Code: [Select]
Memo1.Lines.Text := StringReplace(Memo1.Lines.Text, #13#10, '', [rfReplaceAll]);
« Last Edit: December 27, 2010, 01:38:18 pm by typo »

seba22

  • Full Member
  • ***
  • Posts: 136
Re: Remove newlines (line break) from memo1.text?
« Reply #2 on: December 27, 2010, 01:50:31 pm »
Thank you, this code work for windows and linux ;)

Code: [Select]
  memo3.text:=trim(memo3.text);
  Memo3.Lines.Text := StringReplace(Memo3.Lines.Text, #13#10, '', [rfReplaceAll]);
  Memo3.Lines.Text := StringReplace(Memo3.Lines.Text, #13, '', [rfReplaceAll]);
  Memo3.Lines.Text := StringReplace(Memo3.Lines.Text, #10, '', [rfReplaceAll]);
   
« Last Edit: December 27, 2010, 01:56:41 pm by seba22 »

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Remove newlines (line break) from memo1.text?
« Reply #3 on: December 27, 2010, 02:00:26 pm »
Quote
Maybe i need another line for linux systems ?

Yes.

DirkS

  • Sr. Member
  • ****
  • Posts: 251
Re: Remove newlines (line break) from memo1.text?
« Reply #4 on: December 27, 2010, 02:31:26 pm »
Thank you, this code work for windows and linux ;)

Code: [Select]
  memo3.text:=trim(memo3.text);
  Memo3.Lines.Text := StringReplace(Memo3.Lines.Text, #13#10, '', [rfReplaceAll]);
  Memo3.Lines.Text := StringReplace(Memo3.Lines.Text, #13, '', [rfReplaceAll]);
  Memo3.Lines.Text := StringReplace(Memo3.Lines.Text, #10, '', [rfReplaceAll]);
   
You don't need the first stringreplace; that situation is also covered by the other two.

Gr.
Dirk.

seba22

  • Full Member
  • ***
  • Posts: 136
Re: Remove newlines (line break) from memo1.text?
« Reply #5 on: December 27, 2010, 02:34:41 pm »
Right, You got me  ;)

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Remove newlines (line break) from memo1.text?
« Reply #6 on: December 27, 2010, 11:26:12 pm »
Why don't you use LineEnding instead?

Bart

 

TinyPortal © 2005-2018