< Perl Programming < Keywords
The index keyword
index searches for one string within another without the wildcard-like behavior of a full regular-expression pattern match, and returns the first occurance 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.
Syntax
index STRING, SUBSTRING, POSITION
index STRING, SUBSTRING
Examples
$string = "Abrakaddabra";
$substring = "adda";
print index($string, $substring);
prints the first occurring index, which is 5:
5
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.