Functions for Finding, Comparing and Capturing Data or Strings

These functions help to find, compare and capture data.

Find out whether a value exists in a string

Function

Description

Output

contains(string-original, string-matching)

Checks whether the string-original contains the string-matching; if it does, then it returns the value true. This function is case sensitive.

For example:

${af:contains("OpenMarket", "Mark")}

returns true as "Mark" is in the string "OpenMarket". However:

${af:contains("OpenMarket", "   mark ")}

would return false for either of these reasons:

  • The "m" is now lowercase
  • There is no whitespace in the string "OpenMarket"

Boolean

inList(string-list, string-matching, string-separator)

 

This function is useful when interpreting the response received from the Get External Data handler (such as a list of parameters/XML returned by the handler).

It finds whether the string-matching is in the specified string-list, and returns either true or false. You must specify the character that separates each item in the list, such as a comma, "&" character, or "|" character.

For example:

${af:inList("run=no&swim=yes&cycle=no", "swim=yes", "&")}

returns true, as the function found "swim=yes".

The matching is case-insensitive. The string-matching is also trimmed of whitespace at the beginning and end of the string.

Boolean

Find the position of part of a string

Function

Description

Output

indexOf(original-string, matching-string)

Searches the original-string for the first occurrence of the matching-string. It then returns an integer, specifying the number of characters from the start of the string at which the matching-string is found. For example:

${af:indexOf("Hello from OpenMarket", "Open")}

would return 11.

${af:indexOf("OpenMarket rocks", "Open")}

would return 0.

The function is case-sensitive.

If the matching-string does not occur in the original-string, then the function returns -1.

Integer

Find the length of a string

Function

Description

Output

length(string)

Returns the character length of the string. For example: ${af:length("OpenMarket")} would return 10.

Integer

Compare strings

These functions compare strings. You can also use relational and conditional operators in EL to compare literal values.

Function

Description

Output

regexpMatches(string,regexp)

This function returns a Boolean value depending on whether the string matches the regular expression.

Boolean

equalsIgnoreCase (input,input)

Compares the two strings while disregarding their case. If the strings match, the function returns the value true. The value false is returned otherwise.

For example, you could use it in a competition service to see whether an end user correctly answered "cat" (ignoring the case):

${af:equalsIgnoreCase(session.initialMessage.strippedMessage, "cat")}

Boolean

Capture data from a string

Function

Description

Output

regexpGetCaptureGroup (string, regexp, integer)

This function uses a regular expression to capture a desired part of the specified string. The syntax is the same as used within Java.

The regexp may include multiple capture groups that grab different data segments. The integer refers to the capture group that you want the expression to output, with 1 being the first capture group specified. If there is only one capture group, then you must specify 1 as the integer. The function will output the specified segment of the first matching string that it finds.

String

Capture part of a string

Function

Description

Output

substring(string, start-integer, end-integer)

Returns a section of the string. The integers determine how many characters from the left to begin and end the string. For example:

  • ${af:substring("abc", 1, 3)} returns bc
  • ${af:substring("openmarket", 0, 4)} returns open
  • ${af:substring("openmarket", 1, 8)} returns penmark

String