routine index

Documentation for routine index assembled from the following types:

class Str

From Str

(Str) routine index

multi method index(Str:D: Cool:D $needle --> Int:D)
multi method index(Str:D: Str:D $needle --> Int:D)
multi method index(Str:D: Cool:D $needleCool:D $pos --> Int:D)
multi method index(Str:D: Str:D $needleInt:D $pos --> Int:D)

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.

class Cool

From Cool

(Cool) routine index

Defined as:

multi sub index(Cool $sCool $needleCool $pos = 0)
method    index(Cool:D: |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.