Description
Finds the first occurrence of a substring within a string, optionally starting from a specific offset and ending at a specific position.Syntax
Parameters
Returns
Type: number (integer) The zero-based index of the first occurrence of the substring, or-1 if not found. Returns null if the input string is null.
Examples
Example 1: Basic Search
Example 2: Search with Offset
Example 3: Filtering Nodes by Substring Position
Notes
- Returns
nullif input string isnull - Returns
-1if substring is not found - Uses zero-based indexing
- The
offsetparameter allows starting search from a specific position - The
toparameter limits search to a specific range
See Also
- text.indexesOf - Find all occurrences of a substring
- text.replace - Replace substring occurrences
Frequently Asked Questions
What does flex.text.indexOf return if the substring is not found?
What does flex.text.indexOf return if the substring is not found?
It returns
-1 when the substring is not present in the search range.Is the search case-sensitive?
Is the search case-sensitive?
Yes. The search is case-sensitive. Use
toLower() on both strings if you need case-insensitive matching.