EasyManua.ls Logo

MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE - Indexof (String.indexof Method)

MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE
1378 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
String 1131
indexOf (String.indexOf method)
public indexOf(value:String, [startIndex:Number]) : Number
Searches the string and returns the position of the first occurrence of value found at or after
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
Parameters
value:String - A string; the substring to search for.
startIndex:Number [optional] - An integer specifying the starting index of the search.
Returns
Number - The position of the first occurrence of the specified substring or -1.
Example
The following examples use
indexOf() to return the index of characters and substrings:
var searchString:String = "Lorem ipsum dolor sit amet.";
var index:Number;
index = searchString.indexOf("L");
trace(index); // output: 0
index = searchString.indexOf("l");
trace(index); // output: 14
index = searchString.indexOf("i");
trace(index); // output: 6
index = searchString.indexOf("ipsum");
trace(index); // output: 6
index = searchString.indexOf("i", 7);
trace(index); // output: 19
index = searchString.indexOf("z");
trace(index); // output: -1
See also
lastIndexOf (String.lastIndexOf method)

Table of Contents

Related product manuals