In Cool§
See primary documentation in context for routine rindex
multi rindex(Cool:D $s, Cool:D $needle --> Int:D) multi rindex(Cool:D $s, Cool:D $needle, Cool:D $pos --> Int:D) multi method rindex(Cool:D: Cool:D $needle --> Int:D) multi method rindex(Cool:D: Cool:D $needle, Cool:D $pos --> Int:D)
Coerces the first two arguments (including the invocant in method form) to Str
and $pos
to Int
, and returns the last position of $needle
in the string not after $pos
. Returns Nil
if $needle
wasn't found.
See the documentation in type Str for examples.
In Str§
See primary documentation in context for routine rindex
multi method rindex(Str:D: Str:D $needle --> Int:D) multi method rindex(Str:D: Str:D $needle, Int:D $pos --> Int:D) multi method rindex(Str:D: @needles --> Int:D)
Returns the last position of $needle
in the string not after $pos
. Returns Nil
if $needle
wasn't found.
Since Rakudo version 2020.05, rindex
accepts a list of needles to search the string with, and return the highest index found or Nil
.
Examples:
say "aardvark".rindex: "a"; # OUTPUT: «5» say "aardvark".rindex: "a", 0; # OUTPUT: «0 say "aardvark".rindex: "t"; # OUTPUT: «Nil» say "aardvark".rindex: <d v k>; # OUTPUT: «7»
Other forms of rindex
, including subs, are inherited from Cool
.