Author: Tomas Rutkauskas
I would like to strip all extra/ unnecessary spaces from a string. Meaning, if
there are two or more space characters next to each other, I want to strip all but
one. How can I do this?
Answer:
Solve 1:
1 { ... }2 st := 'This is a test';
3 p: pos(' ', st);
4 while p <> 0 do5 begin6 delete(st, p, 1);
7 p: pos(' ', st);
8 end;
9 { ... }
Solve 2:
10 { ... }11 while pos(' ', st) > 0 do12 st := StringReplace(st, ' ', ' ', [rfReplaceAll]);
13 { ... }