IndexOf()
Returns the position at which a substring occurs within a string. The function uses 1-based indexing—that is, the first character in the string is counted as position 1. A result of 0 indicates that the substring wasn’t found in the source string.
| Marketing Cloud Engagement | ✅ Yes |
| Marketing Cloud Next | ✅ Yes |
This function became available in Marketing Cloud Next during the Summer ’26 release (API version 67.0).
The IndexOf() function has two parameters:
sourceString(string): Required. The string to analyze.substring(string): Required. The character or substring to find the position of.
To use the function, pass it a source string, and the substring that you want to find in that string.
This example finds a single character within a string and returns its position. It uses simple conditional logic to determine which text to output.
The example outputs the result of the function.
This example finds a substring that consists of multiple consecutive characters.
The function returns the position at which the substring begins.