Logo

Programming-Idioms

History of Idiom 219 > diff from v4 to v5

Edit summary for version 5 by Bart:
New Pascal implementation by user [Bart]

Version 4

2020-02-29, 15:31:18

Version 5

2020-02-29, 15:33:07

Idiom #219 Replace multiple spaces with single space

Create string t from the value of string s with each sequence of spaces replaced by a single space.

Explain if only the space characters will be replaced, or the other whitespaces as well: tabs, newlines.

Idiom #219 Replace multiple spaces with single space

Create string t from the value of string s with each sequence of spaces replaced by a single space.

Explain if only the space characters will be replaced, or the other whitespaces as well: tabs, newlines.

Extra Keywords
collapse repeated
Extra Keywords
collapse repeated
Imports
sysutils
Code
  t := s;
  while Pos('  ',t) > 0 do
    t := StringReplace(t, '  ', ' ', [rfReplaceAll]);
Comments bubble
Only removes double spaces.
StringReplace is not recursive, hence the loop.