Flash CS3 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript classes > String > lastIndexOf (String.lastIndexOf method) | |||
Searches the string from right to left and returns the index of the last occurrence of value found before startIndex within the calling string. This index is zero-based, meaning that the first character in a string is considered to be at index 0--not index 1. If value is not found, the method returns -1.
Availability: ActionScript 1.0; Flash Player 5
value:String - The string for which to search.
startIndex:Number [optional] - An integer specifying the starting point from which to search for value.
Number - The position of the last occurrence of the specified substring or -1.
The following example shows how to use lastIndexOf() to return the index of a certain character:
var searchString:String = "Lorem ipsum dolor sit amet.";
var index:Number;
index = searchString.lastIndexOf("L");
trace(index); // output: 0
index = searchString.lastIndexOf("l");
trace(index); // output: 14
index = searchString.lastIndexOf("i");
trace(index); // output: 19
index = searchString.lastIndexOf("ipsum");
trace(index); // output: 6
index = searchString.lastIndexOf("i", 18);
trace(index); // output: 6
index = searchString.lastIndexOf("z");
trace(index); // output: -1
indexOf (String.indexOf method)
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00002163.html