Solved

Remove whitespace from memo

Posted on 2006-11-24
5
313 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:ciuly
ID: 18007070
0
 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 500 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:ciuly
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now