Index of
Function Syntax
int index_of(string search ,string find )
int index_of(string search ,string find ,int start )
- search in the string to search in
- find is the string you're trying to find
- start is the (optional) starting position
This function searches through the string search, looking for the string find. If the optional parameter start is specified, it will start searching from that position inside of search, ignoring everything that comes before start in search. This function returns the position where find first occurs in search. This function returns a 0-indexed value, meaning that the first character of search counts as 0. Note that the return value is still based on the full string search if start is specified; it simply ignores any matches made before that point.
Code Sample
Searches for the letter "c" in the lowercase alphabet.
index_of( "abcdefghijklmnopqrstuvwxyz" , "c" );
Would result in:
Returned: 2
Searches for the "Bob" in a line of text, ignoring the first 3 characters.
index_of( "Bob, ignore me, I said to Bob one day." , "Bob" , 3);
Would result in:
Returned: 26
See Also
Special
If find does not occur in search (or the portion used, when start is specified), this function returns -1.