Article View: borland.public.delphi.language.objectpascal
Article #209Re: Remove Spaces Function
From: John Herbster TeamB
Date: Mon, 26 Jan 2004 17:42
Date: Mon, 26 Jan 2004 17:42
23 lines
1745 bytes
1745 bytes
"valentin tihomirov" <valentin_NOSPAM_NOWORMS@abelectron.com> wrote
> ...
> function RemoveSpaces(var s: string): string;
> ...
I suggest that you speed it up and avoid unnecessarly
allocations with something like the following:
function RemoveSpaces(var s: string): string;
var i, j: integer;
begin
Result := s; j := 0;
For i := 1 to length(Result) do
if (Result[i] > #32)
then begin inc(j); Result[j] := Result[i] end;
If (length(Result) <> j)
then SetLength(Result,j);
end; {UNTESTED}
There is an even more effective way: You could count
the non-blank characters in string "s" before allocating
the string "Result". HTH, JohnH
Technical Details
Message-ID:
<40155186$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40153f7d@newsgroups.borland.com> <401543a6$1@newsgroups.borland.com>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 10:10:50 PST From: "John Herbster \(TeamB\)" <herb-sci1_AT_sbcglobal.net> Newsgroups: borland.public.delphi.language.objectpascal References: <40153f7d@newsgroups.borland.com> <401543a6$1@newsgroups.borland.com> Subject: Re: Remove Spaces Function Date: Mon, 26 Jan 2004 11:42:21 -0600 Lines: 23 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 66.142.147.175 Message-ID: <40155186$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1075138950 66.142.147.175 (26 Jan 2004 09:42:30 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail