Extract String Values

Prev Next

These functions copy the information contained in a target source. They return this information as a text string which can be displayed in a message or evaluated with operators and used in personalization rules or selections.


Function Overview

Function

Description

fn:substring

Returns the subset of a target string as specified by start and end indices.

fn:substringAfter

Extracts the subset of a string following the first occurrence of a specific substring.

fn:substringBefore

Extracts the subset of a string before the first occurrence of a specific substring.

ecm:nvl

Returns the specified object when not a null value.

ecm:extractDomain

Extracts the domain part of the specified email address.

ecm:coalesce

Returns the first not null argument from a specified list of arguments.


fn:substring

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%>

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)}%>

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.

Note

The first character counted in the target string has an index value of 0, not 1. If the end index is negative, for example -1, the subset includes all characters up to the end of the string.


fn:substringAfter

The function fn:substringAfter extracts the subset of a string following the first occurrence of a specific substring. The value returned is a string data type.

Example

A ZIP+4 code such as 12345-6789 is stored in the attribute user['ZipCode']. The following expression returns the part after the hyphen, 6789:

${fn:substringAfter(user['ZipCode'], '-')}

Structure

fn:substringAfter(string, string)

Parameters

Parameter

Description

string

Specifies the target string.

string

The value (substring) used to query the target.


fn:substringBefore

The function fn:substringBefore extracts the subset of a string before the first occurrence of a specific substring. The value returned is a string data type.

Example

Values stored in a group attribute represent prices for accommodations in various cities. Prices are saved as fractional numbers to two decimal places. When the price of a hotel in London is inserted into a message, the decimal values are replaced with a dash and preceded by the pound sign (i.e. 255.85 is converted to £255.-). The function fn:substringBefore extracts the value before the decimal point from the attribute Rate_London as follows:

${fn:substringBefore(group.CustomAttribute['Rate_London'], '.')}

If the current value stored in the custom attribute is 255.85, the string returned by the function is 255. The currency symbol, decimal point and dash (in this example, £255.-) must be added to the result with the additional function ecm:concat. See Format and Encode Strings.

Structure

fn:substringBefore(string, string)

Parameters

Parameter

Description

string

Specifies the target string.

string

The value (substring) used to query the target.


ecm:nvl

The function ecm:nvl returns the specified object when not a null value. Otherwise, a specified default object is returned. The value returned is an object type.

Example

A message greeting is personalized to use the first name of the recipient. Recipients who do not have a first name stored as an attribute are addressed as "Dear Subscriber".

The greeting is inserted into the message with a placeholder, which is constructed as follows:

Dear <%${ecm:nvl(user['FirstName'], 'Subscriber')}%>,

Structure

ecm:nvl(object, object)

Parameters

Parameter

Description

object

Specifies the target object. This object is returned if not null.

object

The default object to be returned when the first parameter is null.


ecm:extractDomain

The function ecm:extractDomain extracts the domain part of the specified email address. If the specified value is null or is not a valid email address, the function returns a null value. The value returned is a string data type.

Example

For the email address jane.doe@example.com, the following expression returns example.com:

${ecm:extractDomain(user['Email'])}

Structure

ecm:extractDomain(string)

Parameters

Parameter

Description

string

Specifies the target string for extraction of the email domain.


ecm:coalesce

The function ecm:coalesce returns the first not null argument from a specified list of arguments. The value returned is an object type.

Example

An expression checks specific attributes and a related data set for values. If any of these sources contains data, content is inserted into a message. Rather than write an InsertIf statement to check each source, a single expression is used:

<%InsertIf expression="${not empty ecm:coalesce(user.CustomAttribute['product ID'], group.CustomAttribute['conversion date'], user.relatedAttribute['Purchases'])}"%>Text<%/InsertIf%>

Structure

ecm:coalesce(object...)

Parameters

Parameter

Description

object

Specifies the target object to be queried. Additional objects can be added as a list, separated by commas.