Documentation for method trim

Documentation for method trim, assembled from the following types:

Str.trim

From Str

trim

method trim(Str:D:) returns Str

Remove leading and trailing white-spces. It can be use 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, once needs to write .=trim

my $line = '   hello world    ';
say '<' ~ $line.trim ~ '>';        # <hello world>
say '<' ~ trim($line) ~ '>';       # <hello world>
$line.trim;
say '<' ~ $line ~ '>';             # <   hello world    >
$line.=trim;
say '<' ~ $line ~ '>';             # <hello world>

See also trim-trailing and trim-leading