In Allomorph§
See primary documentation in context for method substr.
method substr(Allomorph:D: |c)
Calls Str.substr on the invocant's Str value.
In Str§
See primary documentation in context for routine substr.
multi substr(Str:D $s, $from, $chars? --> Str:D) multi substr(Str:D $s, Range $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 and the returned value will be used as the value for the argument. $from is invoked with the length of the original string, while $chars is invoked with remaining character count after $from. 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", 6, 3); # 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»
In Cool§
See primary documentation in context for routine substr.
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.