trim
ErrorsCollection

trim

Synthesised documentation from type/Allomorph type/Cool type/Str

From type/Allomorph

See Original text in context

method trim(Allomorph:D:)

Calls Str.trim on the invocant's Str value.

From type/Cool

See Original text in context

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 $stripped = '  abc '.trim;
say "<$stripped>";          # OUTPUT: «<abc>␤»

From type/Str

See Original text in context

method trim(Str:D: --> 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 $line = '   hello world    ';
say '<' ~ $line.trim ~ '>';        # OUTPUT: «<hello world>␤» 
say '<' ~ trim($line~ '>';       # OUTPUT: «<hello world>␤» 
$line.trim;
say '<' ~ $line ~ '>';             # OUTPUT: «<   hello world    >␤» 
$line.=trim;
say '<' ~ $line ~ '>';             # OUTPUT: «<hello world>␤»

See also trim-trailing and trim-leading.