Skip to content

Commit 0a9ea4c

Browse files
committed
add trim
1 parent e8502de commit 0a9ea4c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lib/Str.pod

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,32 @@ Returns the codepoint number of the first character of the string
291291
292292
Returns a list of codepoint numbers, one for each character in the string.
293293
294+
=head2 trim
295+
296+
method trim(Str:D:) returns Str
297+
298+
Remove leading and trailing white-spces. It can be use both as a method
299+
on strings and as a function. When used as a method it will return
300+
the trimmed string. In order to do in-place trimming, once needs to write
301+
C<.=trim>
302+
303+
304+
my $line = ' hello world ';
305+
say '<' ~ $line.trim ~ '>'; # <hello world>
306+
say '<' ~ trim($line) ~ '>'; # <hello world>
307+
$line.trim;
308+
say '<' ~ $line ~ '>'; # < hello world >
309+
$line.=trim;
310+
say '<' ~ $line ~ '>'; # <hello world>
311+
312+
See also L<trim-trailing> and L<trim-leading>
313+
314+
=head2 trim-trailing
315+
316+
Remove the white-space charecters from the end of a string. See also L<trim>.
317+
318+
=head2 trim-leading
319+
320+
Remove the white-space charecters from the beginning of a string. See also L<trim>.
321+
294322
=end pod

0 commit comments

Comments
 (0)