Functions for Replacing, Concatenating or Encoding Strings

These functions help to find, compare and capture data.

Replace parts of a string

Function

Description

Output

replace(string, string-match, string-replacement)

Replaces a specified segment of a string and returns the new string. The string-match is the segment that, once found, is replaced by the string-replacement. For example:

${af:replace( "Openstore", "store", "Market" )}

would return the string, OpenMarket.

The function only replaces the first instance of the string-match found in the string. If the function does not find a string-match in the original string, then the original string is returned.

String

replaceAll(string, regex-match, string-replacement)

Replaces specified segments of a string and returns the new string. The regex-match is regular expression used to identify the segments to replace. Once found, each segment is replaced by the string-replacement. For example:

${af:replaceAll("This     is   a       sentence       with     too    much    whitespace", "\\s+", " ")

replaces each chunk of whitespace with just one space, and returns the new string: "This is a sentence with too much whitespace".

The function finds and replaces all segments that match the regex-match in the string. If the function does not find a regex-match in the original string, then the original string is returned.

String

leftPad(original-string, size, padding-string)

Pads to the left of the original-string with the padding-string. The size specifies how many characters the new value should be including the original-string. For example: ${af:leftPad("15", 6, "0")} would return 000015.

String

Concatenate two strings together

Function

Description

Output

concat(string, string)

Concatenates the two strings and returns the results. For example: ${af:concat("Open", "Market")} returns OpenMarket.

String

Generate MD5 hash of a string

Function

Description

Output

generateMD5Hash(string)

Generates the MD5 hash for a string. For example: ${af:generateMD5Hash(12515550100)} would return 99c69893efc6a57c7893c1315f597549.

String

URL encode a string

Function

Description

Output

urlencode(string, encoding)

Returns the original string as a URL encoded string. The encoding must be one of:

  • UTF-8
  • MODIFIED_LATIN_9
  • ISO-8859-1

For example to URL encode the message body of an SMS:

${af:urlencode(session.initialMessage.message, "UTF-8")}

String