Solved

Remove whitespace from memo

Posted on 2006-11-24
5
319 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 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

821 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