[fpc-pascal] RE: Trim repeated whitespace from a string

Jeff Pohlmeyer yetanothergeek at gmail.com
Sat May 27 07:07:57 CEST 2006


> Anybody know of a function that can remove (normalize) a string
> by remove all beginning and ending whitespace

uses SysUtils;
S:=Trim(S);


> as well as replace all repeated spaces with a single space.

uses StrUtils;
S:=DelSpace1(S);


> A bonus would be to remove tabs and newlines chars as well

I would convert them to spaces and let the functions above have them...
for i:=1 to length(S) do if ( S[i] in [#9..#13] ) then S[i]:=#32;


 - Jeff



More information about the fpc-pascal mailing list