CARVIEW |
- #index STR,SUBSTR,POSITION
- #index STR,SUBSTR
-
The index function searches for one string within another, but without the wildcard-like behavior of a full regular-expression pattern match. It returns the position of the first occurrence of SUBSTR in STR at or after POSITION. If POSITION is omitted, starts searching from the beginning of the string. POSITION before the beginning of the string or after its end is treated as if it were the beginning or the end, respectively. POSITION and the return value are based at zero. If the substring is not found,
index
returns -1.Find characters or strings:
index("Perl is great", "P"); # Returns 0 index("Perl is great", "g"); # Returns 8 index("Perl is great", "great"); # Also returns 8
Attempting to find something not there:
index("Perl is great", "Z"); # Returns -1 (not found)
Using an offset to find the second occurrence:
index("Perl is great", "e", 5); # Returns 10
Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via the GitHub issue tracker or email regarding any issues with the site itself, search, or rendering of documentation.
The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the Perl issue tracker, the mailing list, or IRC to report any issues with the contents or format of the documentation.