Table of Contents

String.lastIndexOf( ) Method Flash 5

find the last occurrence of a substring in a string
string.lastIndexOf(substring)
string.lastIndexOf(substring, startIndex)

Arguments

substring

A string containing the character or characters for which to search.

startIndex

An optional integer position in string at which to start the search for substring. The string is searched backward from startIndex, which should be in the range of 0 (the first character) to string.length - 1 (the last character). Defaults to string.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. The search is case-sensitive. Use toLowerCase( ) to ensure a case-neutral search, as shown in the Example under String.indexOf( ).

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.html

See Also

String.charAt( ), String.indexOf( ), String.toLowerCase( ); "The lastIndexOf( ) Function," in Chapter 4


Table of Contents