From KoLMafia
Jump to: navigation, search

Function Syntax

int last_index_of(string search ,string find )

int last_index_of(string search ,string find ,int end )

  • search in the string to search in
  • find is the string you're trying to find
  • end is the (optional) ending position (i.e. where the string is truncated before the search is performed)

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.

Code Sample

Returns the last instance of the phrase "la" in the following phrase.

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.

string example = "I'm not listening, la la la la";
last_index_of( example , "la" , length(example) - 3 );
Would result in:
Returned: 25

See Also


If find does not occur in search, this function returns -1.