sub substr

Documentation for sub substr assembled from the following types:

class Cool

From Cool

(Cool) routine substr

Defined as:

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.

class Str

From Str

(Str) routine substr

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);     # RESULT: «g st␤» 
say substr("Long string"63);     # 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␤»