Index of: Difference between revisions
imported>Bale mNo edit summary |
imported>Zarqon m return value for failure |
||
Line 28: | Line 28: | ||
}}| | }}| | ||
function_description=This function searches through the string {{pspan|search}}, looking for the string {{pspan|find}}. If the optional parameter {{pspan|start}} is specified, it will start searching from that position inside of {{pspan|search}}, ignoring everything that comes before {{pspan|start}} in {{pspan|search}}. This function returns the position where {{pspan|find}} first occurs in {{pspan|search}}. This function returns a 0-indexed value, meaning that the first character of {{pspan|search}} counts as 0. Note that the return value is still based on the full string {{pspan|search}} if {{pspan|start}} is specified; it simply ignores any matches made before that point.| | function_description=This function searches through the string {{pspan|search}}, looking for the string {{pspan|find}}. If the optional parameter {{pspan|start}} is specified, it will start searching from that position inside of {{pspan|search}}, ignoring everything that comes before {{pspan|start}} in {{pspan|search}}. This function returns the position where {{pspan|find}} first occurs in {{pspan|search}}, or -1 if {{pspan|find}} was not found. This function returns a 0-indexed value, meaning that the first character of {{pspan|search}} counts as 0. Note that the return value is still based on the full string {{pspan|search}} if {{pspan|start}} is specified; it simply ignores any matches made before that point.| | ||
code1={{CodeSample| | code1={{CodeSample| |
Revision as of 07:14, 25 July 2013
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, or -1 if find was not found. 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 "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 searched, when start is specified), this function returns -1.