indexSTR
,SUBSTR
,POSITION
indexSTR
,SUBSTR
This function returns the position of the first occurrence of SUBSTR
in STR
. The POSITION
, if specified, says where to start
looking.
Positions are based at 0 (or whatever you've set the $[ variable
to - but don't do that).
If the substring is not found, the function returns one less
than the base, ordinarily -1. To work your way through a string, you might
say:
$pos = -1; while (($pos = index($string, $lookfor, $pos)) > -1) { print "Found at $pos\n"; $pos++; }