The function fn:substring returns the subset of a target string as specified by start and end indices. The value returned is a string data type.

Example with personalization

The product ID of a subscriber's most recent purchase is stored in a custom attribute named product ID. In the product catalog, all product numbers for running shoes begin with the number 030. A newsletter is set up to promote a new line of outerwear with a personalized message for runners. This personalization will only be displayed to subscribers that have most recently purchased running shoes. The expression that inserts the personalization is constructed as follows:

<%InsertIf expression="${fn:substring(user.CustomAttribute['product ID'], 0, 3)=='030'}"%>Text<%/InsertIf%>
CODE

In this example, the text is only inserted in the message if the substring returned by the function matches the value 030 included in the expression.

Example for creating dynamic values

An event trigger is configured to export campaign statistics. The groups included in message sendouts have names that begin with a two-digit country code. The trigger is configured to dynamically assign a value for the output directory used to save the export file. The country code is extracted from the group name and inserted as a variable at the end of the FTP URL. This stores the statistics for each country in separate subfolders on the FTP server. The placeholder for adding this variable to the end of the URL is formatted as follows:

<%${fn:substring(group['Name'], 0, 2)}%>
CODE

Structure​

fn:substring(string, integer, integer)

Parameters​

Parameter

Description

string

Specifies the target string.

integer

The index of the first character to be included in the subset.

integer

The index of the first character to be excluded from the subset.

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