String Functions
CSL supports the following predefined functions for the manipulation of strings.
Conversion Functions
These functions convert between strings and numbers.
asNumber(s)
Converts the string s to a double.
asString(n)
Converts the number n to a string. Note that n is interpreted as a double and may often have more digits after the decimal than expected. Use in conjunction with mid() to reduce to simple form if desired.
downCase(s)
Modifies a string so that it is all lowercase; that is, converts all uppercase alphabetic characters to their lowercase equivalent. If s is a number, this function converts it to a string.
htmlEscape(s)
Returns a version of the string with any reserved HTML characters replaced by their associated HTML entities. For example, '<' is replaced with '&lt;'; '&' is replaced with '&amp;'. The resulting string can be displayed safely in HTML-formatted fields.
upcase(s)
Modifies a string so that it is all uppercase; that is, converts all lowercase alphabetic characters to their uppercase equivalent. If s is a number, this function converts it to a string.
Index Functions
These functions return a string index that meets a specified condition.
index(s1, s2)
Returns the start index of the first occurrence of string s2 in string s1. The smallest index is 1 (that is, indexes are 1-based, not 0-based). Returns -1 if s2 does not occur in s1.
index(s1, s2, i)
Returns the start index of the first occurrence of string s2 that starts at or after index i in string s1. The smallest index is 1 (that is, indexes are 1-based, not 0-based). Note that index(s1, s2, 1) is equivalent to index(s1, s2). Returns -1 if there is no such occurance.
lastIndex(s1, s2)
Returns the start index of the last occurrence of string s2 in string s1. The smallest index is 1 (that is, indexes are 1-based, not 0-based). Returns -1 if s2 does not occur in s1.
lastIndex(s1, s2, i)
Returns the start index of the last occurrence of string s2 that starts at or before index i in string s1. The smallest index is 1 (that is, indexes are 1-based, not 0-based). Returns -1 if s2 does not occur in s1.
len(s)
Returns the length of the string s.
Substring Functions
These functions return a substring that meets a specified condition.
mid(s, i)
Returns the trailing substring of string s whose first character is at index i.
mid(s, i, j)
Returns the substring of string s that whose first character is at index i and whose last character is at index j-1. The character at index j is not included in the returned string.
prefix(s1, s2)
Returns the leading substring of string s1 whose last character is immediately before the first occurrence of s2 in s1. If s2 is not found or is equivalent to s1, the empty string is returned.
searchString(string, regular-expression)
Returns a list of sub-strings from the specified string that match the specified regular expression pattern. The second argument must evaluate to a regular expression, as described in http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html. See also Like Expressions.
splitString(string, regular-expression)
Returns a list of sub-strings created by splitting the original string whenever the separator string is found. The separator string is typically a single character, but can be a regular expression. Any whitespace before or after each of the resulting sub-strings is automatically trimmed. Examples:
splitString('abc:def:ghi', ':') returns ['abc', 'def', 'ghi']
splitString('abc.def.ghi', '\\.') returns ['abc', 'def', 'ghi'] (Note that '.' has to be escaped as '\\.' in the separator expression.)
suffix(s1, s2)
Returns the substring of s1 that immediately follows the first character of the last occurrence of s2 in s1. Typically s2 is one character in length. Note that if s2 is more than one character in length, the returned string includes all characters of s2 except the first. If s2 is not found or matches the last character of s1, the empty string is returned.
suffix2(s1, s2)
Returns the substring of string s1 that immediately follows the last character of the last occurrence of s2 in s1. If s2 is not found, is equivalent to s1, or matches a trailing substring of s1, the empty string is returned.