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.

Availability 

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).

Syntax 

1IndexOf(sourceString, substring)

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.

Usage 

To use the function, pass it a source string, and the substring that you want to find in that string.

Finding a Single Character 

This example finds a single character within a string and returns its position. It uses simple conditional logic to determine which text to output.

1%%[
2  Var @tickedId, @isTicketClassC
3  Set @ticketId = "29487C-22934"
4  Set @isTicketClassC = IndexOf(@ticketId, "C")
5  If @isTicketClassC == 6 then
6]%%
7<p>Your ticket is Class C</p>
8%%[ Else ]%%
9<p>Your ticket is not Class C</p>
10%%[ EndIf ]%%

The example outputs the result of the function.

1Your ticket is Class C

Finding a Substring with Multiple Characters 

This example finds a substring that consists of multiple consecutive characters.

1%%[
2  Var @lipsum, @position, @substringToFind
3  Set @lipsum = "Lorem ipsum dolor sit amet."
4  Set @substringToFind = "dolor"
5  Set @position = IndexOf(@lipsum, @substringToFind)
6]%%
7<p>Found the string "%%=v(@substringToFind)=%%" at position %%=v(@position)=%%.</p>

The function returns the position at which the substring begins.

1Found the string "dolor" at position 13.