Name
String.lastIndexOf( ) Method — find the last occurrence of a substring in a string
Availability
Flash 5
Synopsis
string.lastIndexOf(substring) string.lastIndexOf(substring, startIndex)
Arguments
- substring
A string containing the character or characters to search for.
- startIndex
An optional integer position in
stringat which to start the search forsubstring. Thestringis searched backward fromstartIndex, which should be in the range 0 (the first character) tostring.length-1(the last character). Defaults tostring.length-1.
Returns
The position of the last occurrence of
substring in
string prior to
startIndex. Returns -1 if
substring is not found prior to
startIndex in
string.
Description
The lastIndexOf( ) method is used to search for
the last occurrence of a substring in a string or to check whether a
string contains a certain substring.
Example
URL = "http://www.moock.org/webdesign/flash/fillthewindow.html";
// Finds the last slash character
lastSlash = URL.lastIndexOf("/");
// Extracts the filename from the URL
file = URL.substring(lastSlash + 1);
trace(file); // Displays: fillthewindow.htmlSee Also
String.charAt( ), String.indexOf(
); Section 4.6.5.4 in Chapter 4
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access