Skip to main content

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

Output:

Example 2: Search with Offset

Output:
(Finds the second “hello” starting from position 3)

Example 3: Filtering Nodes by Substring Position

Notes

  • Returns null if input string is null
  • Returns -1 if substring is not found
  • Uses zero-based indexing
  • The offset parameter allows starting search from a specific position
  • The to parameter limits search to a specific range

See Also

Frequently Asked Questions

It returns -1 when the substring is not present in the search range.
Yes. The search is case-sensitive. Use toLower() on both strings if you need case-insensitive matching.