Perl Programming/Keywords/index
< Perl Programming | Keywords
The index keywordEdit
index searches for one string within another without the wildcard-like behavior of a full regular-expression pattern match, and returns the first occurrence index of SUBSTRING in STRING. If also POSITION is passed, the search stars from this position. If POSITION points before the beginning of or after the end of the string, it is regarded as if it points to the beginning or end of it, respectively.
The return value is -1, if SUBSTRING is not found.
SyntaxEdit
index STRING, SUBSTRING, POSITION
index STRING, SUBSTRING
ExamplesEdit
$string = "Abrakaddabra";
$substring = "adda";
print index($string, $substring);
prints the first occurring index, which is 5:
5