Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 03-01-2010, 12:14 PM
beh.tehrani beh.tehrani is offline
Senior Member
 
Join Date: Mar 2009
Posts: 316
Question Delete all empty lines inside memo

Hello

i want Delete all empty lines inside memo.

this code only delete empty line in end of memo;
Code:
Memo1.Text:=Trim(Memo1.text);
but i need to delete all empty line inside memo.

thanks
Reply With Quote
  #2  
Old 03-01-2010, 02:51 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,059
Default

Try:


Code:
var
          i : Integer;
begin
          for i:=Memo1.Lines.Count-1 downto 0 do begin
              if Trim(Memo1.Lines[i]) = '' then
                 Memo1.Lines.Delete(i);
          end;
__________________
Regards,
Abdulaziz Jasser
Reply With Quote
  #3  
Old 03-01-2010, 03:45 PM
beh.tehrani beh.tehrani is offline
Senior Member
 
Join Date: Mar 2009
Posts: 316
Smile thanks

thanks jasser
Reply With Quote
  #4  
Old 08-26-2016, 06:29 PM
beryindo beryindo is offline
Junior Member
 
Join Date: Jun 2016
Posts: 9
Default

Quote:
Originally Posted by Jasser View Post
Try:


Code:
var
          i : Integer;
begin
          for i:=Memo1.Lines.Count-1 downto 0 do begin
              if Trim(Memo1.Lines[i]) = '' then
                 Memo1.Lines.Delete(i);
          end;
Work, but fery slow if many line in Tmemo, any solusition ?
Reply With Quote
  #5  
Old 08-27-2016, 02:39 AM
rojam rojam is offline
Senior Member
 
Join Date: Jun 2015
Posts: 199
Default

try enclosing Jassar's code within Begin/End Updates
Code:
var
  i : Integer;
begin
  Memo1.Lines.BeginUpdate;
  try
    for i:=Memo1.Lines.Count-1 downto 0 do
      if Trim(Memo1.Lines[i]) = '' then
        Memo1.Lines.Delete(i);
  finally
    Memo1.Lines.EndUpdate;
  end;
end;
That will postpone the control from updating the GUI until the entire contents has been processed.
Reply With Quote
  #6  
Old 09-05-2016, 10:01 AM
lexd lexd is offline
Senior Member
 
Join Date: Feb 2015
Posts: 268
Default

TMemo.Lines is really a TStringlist, so why not TMemo.Lines.Clear
Reply With Quote
  #7  
Old 09-05-2016, 10:08 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,059
Default

"Clear" will delete ALL lines not only the empty ones. Try the next line:


Code:
Memo1.Lines.Text := StringReplace(Memo1.Lines.Text,Char(13)+Char(10)+Char(13)+Char(10),'',[rfReplaceAll]);
Or

Code:
Memo1.Lines.Text := StringReplace(Memo1.Lines.Text,Char(13)+Char(10)+Char(13)+Char(10),Char(13)+Char(10),[rfReplaceAll]);
__________________
Regards,
Abdulaziz Jasser

Last edited by Jasser; 09-05-2016 at 10:14 AM.
Reply With Quote
  #8  
Old 09-05-2016, 10:19 AM
lexd lexd is offline
Senior Member
 
Join Date: Feb 2015
Posts: 268
Default

Thanks Jasser I did not catch the delete empty lines bit
You are correct.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 08:20 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.