Solved

Delete "White Spaces" in TMemo

Posted on 2004-09-08
3
410 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 20 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi 2 92
How to debug For loops? 3 75
Can Live bindings change TGrid Cell Colour ? 1 64
Firemonkey how to swip panel with finger tap 1 42
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

752 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