The function fn:indexOf returns the index within a string of a specified substring. The value returned is an integer data type.

Example

Customer purchase orders are stored in a related data set. The product names include a model number. The related data set is called ​Orders​ and is linked to the user attribute ​user.Email​. The model number is preceded by a forward slash character (/). The product name is inserted into a message without the product number.

This example uses the function fn:indexOf to determine the index number of the special character and extract only the product name using the fn:substring function (see fn:substring​). The function for locating the index of the forward slash is constructed as follows:

fn:indexOf(user.relatedAttribute['Orders']['ProductName'], "/")
CODE

The function returns an integer which equals the index of the special character. When used inside a fn:substring function that returns only the product name, it appears as follows:

${fn:substring(user.relatedAttribute['Orders']['ProductName'], "", fn:indexOf(user.relatedAttribute['Orders']['ProductName'], "/"))}
CODE

In this example, the result returned from the fn:indexOf function is used as the parameter that defines the first character to be excluded from the substring. The parameter that defines the first character to be included is left blank. The substring returned includes anything that precedes the forward slash, no matter where it appears in the data set. Given that there can be more than one order per user in the data set, a ​ForEach​ loop is used to include all the order information in a message. For more information on constructing a ​ForEach​ loop, see  Insert Related Data Records Into Messages​ .

The first character counted in the target string has an index value of 0, not 1.

Structure​

fn:indexOf(string, string)

Parameters​

Parameter

Description

string

Specifies the target string.

string

The value (substring) used to query the target.