Solved

Remove whitespace from memo

Posted on 2006-11-24
5
320 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
[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
  • 2
  • 2
5 Comments
 
LVL 28

Expert Comment

by:2266180
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: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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
Delphi component that can load a DLL in design time? 8 107
Delphi 2 91
Breakpoint doesn't stop in my variable 3 48
MS Access from Delphi 31 104
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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…

751 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