Indexof (String.indexof Method) - MACROMEDIA FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE Reference

Flash lite 2.x actionscript language reference
Hide thumbs Also See for FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE:
Table of Contents

Advertisement

indexOf (String.indexOf method)

public indexOf(value:String, [startIndex:Number]) : Number
Searches the string and returns the position of the first occurrence of
found at or after
value
within the calling string. This index is zero-based, meaning that the first
startIndex
character in a string is considered to be at index 0--not index 1. If
is not found, the
value
method returns -1.
Availability: ActionScript 1.0; Flash Lite 2.0
Parameters
- A string; the substring to search for.
value:String
[optional] - An integer specifying the starting index of the search.
startIndex:Number
Returns
- The position of the first occurrence of the specified substring or -1.
Number
Example
The following examples use
to return the index of characters and substrings:
indexOf()
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)
String
631

Advertisement

Table of Contents
loading

Table of Contents