Link Search Menu Expand Document

UString.LastIndexOf Method

Explanation Finds the specified string up to pos and returns the last found position.
Call format var n = str.LastIndexOf( find [, pos ] )
Return value Returns a zero -based number indicating the location found . Returns -1 if not found.
Arguments UString 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 UString("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