Functions Related to Text or Characters in a String

The following functions are related to altering the text in a string.

Remove digits, letters, or punctuation from a string

Function

Description

Output

removeDigits(input)

Returns a string with all characters except digits.

String

removeLetters(input)

Returns a string with all characters except letters.

String

removePunctuation(input)

Returns a string with only digits, letters and whitespace. For example, you could use the following expression to remove punctuation from SMS message text before it is sent to an external platform:

${af:removePunctuation(session.initialMessage.strippedMessage)}

String

Remove whitespace from a string

The following functions read the specified string and remove whitespace from the string.

Function

Description

Output

trim(string)

Returns a string with the white space removed from either side of the original string. For example:

${af:trim("   cat and dog     ")}

would return "cat and dog".

String

trimLeft(string)

Returns a string with the white space removed from the left of the original string. For example:

${af:trim("   fish and chips   ")}

would return "fish and chips   ".

String

trimRight(string)

Returns a string with the white space removed from the right of the original string. For example:

${af:trim("   black and white   ")}

would return "    black and white".

String

Change text into either upper or lower case

Function

Description

Output

toLowerCase(input)

Returns a string with all letters in lower case. For example, you could use toLowerCase(input) as a way of making this expression case insensitive:

${af:toLowerCase(session.initialMessage.strippedMessage) == "cat"}

String

toUpperCase(input)

Returns a string with all letters in upper case. For example, you could use toUpperCase(input) as a way of making this expression case insensitive:

${af:toUpperCase(session.initialMessage.strippedMessage) == "DOG"}

String