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

x
?
Solved

Remove whitespace from memo

Posted on 2006-11-24
5
Medium Priority
?
326 Views
Last Modified: 2010-04-05
Does anybody know how to remove whitespace from a memo?

Blank lines being whitespace
and also any blank spaces like this "the cat                              sat on the mat, have                   a nice day"

Thanks
0
Comment
Question by:zattz
  • 2
  • 2
5 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 18007070
0
 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 2000 total points
ID: 18007469
There is a lot to go through in that link, so I put together a function for you to do what you asked for:

procedure StripWhiteSpaces(AMemo: TMemo);
var p1,p2: pchar;
    s: string;
    i: integer;
begin
  s:= AMemo.Lines.Text;
  if s = '' then exit;

  p1:= pchar(s);
  p2:= p1;
  while p2^ <> #0 do
  begin
    if (p2^ = ' ') AND ((pchar(p2+1)^ = ' ') or (pchar(p2-1)^ in [#13,#10]))
      then Delete(s, p2 - p1 + 1,1)
      else inc(p2);
  end;
  AMemo.Lines.Text:= trim(s);
  for i:= AMemo.Lines.Count-1 downto 0 do
    if AMemo.Lines[i] = ''
      then AMemo.Lines.Delete(i);
end;

Regards
Pierre
0
 
LVL 28

Expert Comment

by:2266180
ID: 18007534
that will teach me to choose a function and not just give a link to the list of functions. though it should have been more correct to at least mark my resonse as assisted.
whatever.
0
 

Author Comment

by:zattz
ID: 18007555
noted...
0
 

Author Comment

by:zattz
ID: 18017796
Hi Pierre,

I need the procedure altered to work with VCL.NET so I've opened a new question. I thought i'd paste it here incase you were interested:

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

0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
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…

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