last_index_of
Function Syntax
int last_index_of( string search, string find, int? )
- Returns the last index of the second string in the first, or -1 if no match is found.
- search: String to search in
- find: String you're trying to find
- : (optional) ending position. If omitted, this defaults to
length(search)
.
This function searches through the string search, looking for the string find. This function returns the position where find last occurs in search.
This function returns a 0-indexed value, meaning that the first character of search counts as 0.
If find does not occur in search, this function returns -1.
Code Sample
Returns the last instance of the phrase "la" in the following phrase.
// Matched at:
// vv
last_index_of( "I'm not listening, la la la la" , "la" );
Would result in:
Returned: 28
Returns the last instance of the phrase "la", ignoring the last three characters.
// Matched at:
// vv
string example = "I'm not listening, la la la la";
last_index_of( example , "la" , length(example) - 3 );
Would result in:
Returned: 25