Convert string with two spaces to one space

Hi,

Would like to convert the string. eg "Alexander  Master" to "Alexander Master".

Any idea ?
n_chaiAsked:
Who is Participating?
 
ddaCommented:
my $s = "Alexander  Master";
print "was: [$s]\n";
$s =~ s/\s\s/ /g;
print "now: [$s]\n";
0
 
andreifCommented:
please, review your previous questions - you did not accept neither reject solutions
0
 
yorenCommented:
Try this to shrink blocks of whitespace into a single space:

my $s = "Alexander  Master   Jedi";
$s =~ s/\s+/ /g;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.