text.indexOf
Description
Finds the first occurrence of a substring within a string, optionally starting from a specific offset and ending at a specific position.
Syntax
flex.text.indexOf(string, substring, offset, to)
Parameters
| Parameter | Type | Required | Description | |———–|——|———-|————-| | string | string | Yes | The string to search in | | substring | string | Yes | The substring to search for | | offset | number | No | Starting position for search (default: 0) | | to | number | No | Ending position for search (default: -1, meaning end of string) |
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
RETURN flex.text.indexOf('hello world', 'world') AS position
Output:
position
--------
6
Example 2: Search with Offset
RETURN flex.text.indexOf('hello hello', 'hello', 3) AS position
Output:
position
--------
6
(Finds the second “hello” starting from position 3)
Example 3: Filtering Nodes by Substring Position
MATCH (p:Product)
WHERE flex.text.indexOf(p.description, 'premium') >= 0
RETURN p.name, p.description
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