Documentation for sub
substr assembled from the following types:
sub substr(Str(Cool) , |c)method substr(|c)
multi sub substr(Str , , ? --> Str)multi sub substr(Str , Range --> Str)multi method substr(Str : , ? --> Str)multi method substr(Str : Range --> Str)
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 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
$chars are not Callable, they'll be coerced to Int.
$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); # RESULT: «g st␤»say substr("Long string", 6, 3); # RESULT: «tri␤»say substr("Long string", 6); # RESULT: «tring␤»say substr("Long string", 6, *-1); # RESULT: «trin␤»say substr("Long string", *-3, *-1); # RESULT: «in␤»