🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.language.objectpascal
Article #204

Remove Spaces Function

#204
From: Yehia Ahmed
Date: Mon, 26 Jan 2004 16:15
48 lines
2369 bytes
hello,
I wrote this procedure which remove the spaces after and before the "equal"
sign,
for example --> test        =                  test2
      becomes--> test = test2
and -->test=test2
     becomes-->test = test2
(like the visual basic editor)
my function was like this:

Procedure RemoveSpaces (Ln:integer);
var ReStr:String;
    Re,re,i:integer;
    F1,F2:boolean;
begin
ReStr := maintext.lines[ln-1];
Re:= instrmt('=',lnbegin,toend - lnbegin ,[ ],true,true); -->just like
maintext.findtext (maintext is a richedit)
Re2:= firstcolumn(ln) -1;
repeat
if re <> -1 then begin
   Restr[Re -re2]:= '`';
   for i := 1 to length(restr) do begin
      try
         if (restr[re - i -re2] = ' ') And(f1=false) then restr[re -
i -re2]:= '`' else f1 := true;
         if (restr[re + i -re2] = ' ') And(f2=false) then restr[re + i-re2]
:= '`' else f2 := true;
         if (f1=true) and (f2=true) then break;
      except
         //
      end;
   end;
Re:= instrmt('=',Re+1 ,toend - lnbegin ,[],true,true);
end;
until Re= -1;
ReStr:= StringReplace(restr,'%',' = ',[rfreplaceall]); ---> error occurs
here!!
ReStr:= StringReplace(restr,'`','',[rfreplaceall]);
maintext.lines[ln-1] := ReStr;
end;

this procedure is extremely slow when loading text from a file cause it's
called on every line, sometimes there is strange EAccessViolation error on
the stringreplace line(still don't know why), anyone can help me to improve
a better procedure?

Yehia
Technical Details
Message-ID: <40153f7d@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109d30,8b4ceee2931b0643
X-Google-Attributes: gid109d30,public
X-Google-ArrivalTime: 2004-01-26 08:43:21 PST
From: "Yehia Ahmed" <yehiaeg@hotmail.com>
Newsgroups: borland.public.delphi.language.objectpascal
Subject: Remove Spaces Function
Date: Mon, 26 Jan 2004 18:15:11 +0200
Lines: 51
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2720.3000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2727.1300
NNTP-Posting-Host: 62.68.242.51
Message-ID: <40153f7d@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1075134333 62.68.242.51 (26 Jan 2004 08:25:33 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail