my $string = ' Mary had a little lamb. '; $string =~ s/^\\s+//; #remove leading spaces $string =~ s/\\s+$//; #remove trailing spaces print $string;
You are here: Home > regex > Remove leading and trailing white space from a string
Tuesday, May 08, 2007
Subscribe to:
Post Comments (Atom)
1 comments:
Needs a slight correction:
$string =~ s/^\s+//;
$string =~ s/\s+$//;
Post a Comment