String.indexof() - MACROMEDIA FLASH MX 2004-ACTIONSCRIPT LANGUAGE Reference

Actionscript language reference
Table of Contents

Advertisement

String.indexOf()

Availability
Flash Player 5.
Usage
my_str.indexOf(substring:String, [startIndex:Number])
Parameters
A string; the substring to be searched for within
substring
A number; an optional integer specifying the starting point in
startIndex
the substring.
Returns
A number; the position of the first occurrence of the specified substring or -1.
Description
Method; searches the string and returns the position of the first occurrence of
found at or after
first character in a string is considered to be at index 0—not index 1. If
the method returns -1.
Example
The following examples use
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
String.lastIndexOf()
within the calling string. This index is zero-based, meaning that the
startIndex
indexOf()
to return the index of characters and substrings:
.
my_str
my_str
substring
is not found,
substring
String.indexOf()
to search for
799

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004-ACTIONSCRIPT LANGUAGE and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Flash mx

Table of Contents