Documentation for routine trim
assembled from the following pages:
Class: Allomorph §
From Allomorph
(Allomorph) method trim §
method trim(Allomorph:)
Calls Str.trim
on the invocant's Str
value.
Class: Str §
From Str
(Str) method trim §
method trim(Str: --> Str)
Remove leading and trailing whitespace. It can be used both as a method on strings and as a function. When used as a method it will return the trimmed string. In order to do in-place trimming, one needs to write .=trim
my = ' hello world ';say '<' ~ .trim ~ '>'; # OUTPUT: «<hello world>» say '<' ~ trim() ~ '>'; # OUTPUT: «<hello world>» .trim;say '<' ~ ~ '>'; # OUTPUT: «< hello world >» .=trim;say '<' ~ ~ '>'; # OUTPUT: «<hello world>»
See also trim-trailing and trim-leading.
Class: Cool §
From Cool
(Cool) routine trim §
Defined as:
sub trim(Str(Cool))method trim()
Coerces the invocant (or in sub form, its argument) to Str, and returns the string with both leading and trailing whitespace stripped.
my = ' abc '.trim;say "<$stripped>"; # OUTPUT: «<abc>»