Link Search Menu Expand Document

String.LastIndexOf Method

Explanation Finds the specified string up to pos and returns the last found position.

This method finds without being aware of the character type of the target character string. Use the find function to search for double-byte characters in the target string
Call format var n = str.LastIndexOf( find [, pos ] )
Return value Returns a zero -based number that indicates the location found. Returns -1 if not found
Arguments String find Character string to find
integer pos End position of search range
Specify a number starting from 0. If omitted, the search will be performed to the end.
Exception Func-4 Invalid argument
Example of use
var str1 = new String("abcdefg abcdefg");
print(str1.LastIndexOf("cd"), "\n");
 
 
/* When the target character string contains double-byte characters */
var str2 = new String("東京都千代田区千代田1番1号");
var last = -1;
while (true) {
    var idx = find(str2, "1", last + 1);
    if (idx < 0) {
        break;
    }
    last = idx;
}
print(last, "\n");
    
Related item IndexOf method
find method