Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Delete "White Spaces" in TMemo

Posted on 2004-09-08
3
Medium Priority
?
415 Views
Last Modified: 2010-04-16
Hello All;

   I need to "Delete White Spaces"

I need all White Spaces in a TMemo to be deleted.

Example:
( Memo Outline )

-------------TOP----------------


above is "3" White Spaces
Below is "3" White Spaces



------------Bottom--------------

I need to have this located under a Button.

Any idea's on this will be great.

carrzkiss
0
Comment
Question by:Wayne Barron
3 Comments
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12007189
To remove spaces:
Memo1.Lines.Text := StringReplace(Memo1.Lines.Text, #32, '', [rfReplaceAll]);

To remove empty lines:
Memo1.Lines.Text := StringReplace(Memo1.Lines.Text, #13#10#13#10, #13#10, [rfReplaceAll]);
0
 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 80 total points
ID: 12007896
Alex, your method won't work. e.g. if you have 2 blank lines, it will only delete the first line. You would have to repeat that statement until there are no more #13#10#13#10 pairs found.

Here's another way:

procedure RemoveBlankLines(var m: TMemo);
var i: integer;
begin
  i:= 0;
  while i < m.Lines.Count do
  begin
    if m.Lines[i] = '' then m.Lines.Delete(i) else i:= i+1;
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  RemoveBlankLines(Memo1);
end;

Regards
Pierre
0
 
LVL 31

Author Comment

by:Wayne Barron
ID: 12008512
Thank you [Pierre];

  Your code works very well.

Thank You for your time again, in this post.
I awarded you the points because your code works well.
Even though with the last question that I asked, that you both
Were a part of, this code here does it all.

for Q :=Memo1.Lines.Count -1 downto 0 do
 begin
  if pos( 'http://', lowercase(Memo1.Lines[Q]) ) = 0
   then Memo1.Lines.Delete(Q);
 end;

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21123097.html

From Everst

Thank you all

Wayne
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question