routine index
Documentation for routine index
assembled from the following types:
class Cool
From Cool
(Cool) routine index
Defined as:
multi sub index(Cool , Cool , Cool = 0)method index(Cool: |c)
Coerces the first two arguments (in method form, also counting the invocant) to a Str, and searches for $needle
in the string $s
starting from $startpos
. It returns the offset into the string where $needle
was found, and an undefined value if it was not found.
See the documentation in type Str for examples.
class Str
From Str
(Str) routine index
multi method index(Str: Cool --> Int)multi method index(Str: Str --> Int)multi method index(Str: Cool , Cool --> Int)multi method index(Str: Str , Int --> Int)
Searches for $needle
in the string starting from $pos
(if present). It returns the offset into the string where $needle
was found, and Nil
if it was not found.
Examples:
say index "Camelia is a butterfly", "a"; # OUTPUT: «1»say index "Camelia is a butterfly", "a", 2; # OUTPUT: «6»say index "Camelia is a butterfly", "er"; # OUTPUT: «17»say index "Camelia is a butterfly", "Camel"; # OUTPUT: «0»say index "Camelia is a butterfly", "Onion"; # OUTPUT: «Nil»say index("Camelia is a butterfly", "Onion").defined ?? 'OK' !! 'NOT'; # OUTPUT: «NOT»
Other forms of index, including a sub, are inherited from Cool
. Check them there.