indexOf
Description
Returns the position of the first occurrence of a substring within a string.
The index is zero-based. If the substring is not found, the function returns -1.
Syntax
Like many functions in DataPrime, indexOf supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
| value | string | true | The full string to search (haystack) |
| substring | string | true | The substring to locate (needle) |
Example
Extract a value from a key-value style string
Consider the following document:
Use indexOf to find the position of = and then extract everything after it.
Example query
Example output
With the index known, you can extract the substring:
Result:
Theme
Light