substr
ErrorsCollection

substr

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

From type/Allomorph

See Original text in context

method substr(Allomorph:D: |c)

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

From type/Cool

See Original text in context

sub substr(Str(Cool$str|c)
method substr(|c)

Coerces the invocant (or in the sub form, the first argument) to Str, and calls Str.substr with the arguments.

From type/Str

See Original text in context

multi sub    substr(Str:D $s$from$chars?  --> Str:D)
multi sub    substr(Str:D $sRange  $from-to --> Str:D)
multi method substr(Str:D $s: $from$chars?  --> Str:D)
multi method substr(Str:D $s: Range $from-to  --> Str:D)

Returns a substring of the original string, between the indices specified by $from-to's endpoints (coerced to Int) or from index $from and of length $chars.

Both $from and $chars can be specified as Callable, which will be invoked with the length of the original string and the returned value will be used as the value for the argument. If $from or $chars are not Callable, they'll be coerced to Int.

If $chars is omitted or is larger than the available characters, the string from $from until the end of the string is returned. If $from-to's starting index or $from is less than zero, X::OutOfRange exception is thrown. The $from-to's ending index is permitted to extend past the end of string, in which case it will be equivalent to the index of the last character.

say substr("Long string"3..6);     # OUTPUT: «g st␤» 
say substr("Long string"63);     # OUTPUT: «tri␤» 
say substr("Long string"6);        # OUTPUT: «tring␤» 
say substr("Long string"6*-1);   # OUTPUT: «trin␤» 
say substr("Long string"*-3*-1); # OUTPUT: «in␤»