String.lastIndexOf( ) Method

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
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



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net