Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Delete "White Spaces" in TMemo

Posted on 2004-09-08
3
Medium Priority
?
413 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 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

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

660 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