The trim routine

Combined from primary sources listed below.

In class Str ( Type/Str )§

See primary docmentation in context for method trim.

method trim§

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.

In class Str ( Type/Str )§

See primary docmentation in context for method trim.

method trim-trailing§

method trim-trailing(Str:D: --> Str)

Removes the whitespace characters from the end of a string. See also trim.

In class Str ( Type/Str )§

See primary docmentation in context for method trim.

method trim-leading§

method trim-leading(Str:D: --> Str)

Removes the whitespace characters from the beginning of a string. See also trim.

In class Cool ( Type/Cool )§

See primary docmentation in context for routine trim.

routine trim§

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>␤»

In class Cool ( Type/Cool )§

See primary docmentation in context for routine trim.

routine trim-trailing§

sub trim-trailing(Str(Cool))
method trim-trailing()

Coerces the invocant (or in sub form, its argument) to Str, and returns the string with trailing whitespace stripped.

my $stripped = '  abc '.trim-trailing;
say "<$stripped>";          # OUTPUT: «< abc>␤»

In class Cool ( Type/Cool )§

See primary docmentation in context for routine trim.

routine trim-leading§

sub trim-leading(Str(Cool))
method trim-leading()

Coerces the invocant (or in sub form, its argument) to Str, and returns the string with leading whitespace stripped.

my $stripped = '  abc '.trim-leading;
say "<$stripped>";          # OUTPUT: «<abc >␤»

In class Allomorph ( Type/Allomorph )§

See primary docmentation in context for method trim.

method trim§

method trim(Allomorph:D:)

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

In class Allomorph ( Type/Allomorph )§

See primary docmentation in context for method trim.

method trim-leading§

method trim-leading(Allomorph:D:)

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

In class Allomorph ( Type/Allomorph )§

See primary docmentation in context for method trim.

method trim-trailing§

method trim-trailing(Allomorph:D:)

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