sub index

Documentation for sub index, assembled from the following types:

class Cool

From Cool

(Cool) routine index

Defined as:

multi sub    index(Str(Cool$sStr:D $needleInt(Cool$startpos = 0 --> Int)
multi method index(Str(Cool$needleInt(Cool$startpos = 0 --> Int)

Coerces the first two arguments (in method form, also counting the invocant) to Str, and searches for $needle in the string 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 sub    index(Cool $sStr:D $needleCool $startpos = 0 --> Int)
multi method index(Cool $needleCool $startpos = 0 --> Int)

Searches for $needle in the string starting from $startpos. It returns the offset into the string where $needle was found, and an undefined value 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␤»