Logo

Programming-Idioms

History of Idiom 219 > diff from v12 to v13

Edit summary for version 13 by programming-idioms.org:
New Perl implementation by user [programming-idioms.org]

Version 12

2020-04-29, 09:20:33

Version 13

2020-05-03, 19:27:44

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
Code
my $t = $s;
$s =~ s/\s+/ /;

Comments bubble
Replace all whitespace