Skip to main content

String Functions

Match Functions

  • startsWith(x, term): Checks if the string x starts with the passed term. Matches are case-sensitive.

  • endsWith(x, term): Checks if the string x ends with the passed term. Matches are case-sensitive.

  • contains(x, term): For strings, checks if x contains the substring term anywhere (case-sensitive). For arrays, checks if term is an element of x. Array elements are compared as strings, so contains(arr, 5) will match an element whose string value is "5".

  • equalText(a, b): Checks if a and b are equal as strings (both are converted to strings before comparing). Useful when comparing identifiers that may be numbers or strings interchangeably.

  • match(x, pattern) or match(x, pattern, group): Checks if string x contains a match for given pattern and returns the match. If a group number is provided, only the matching subgroup will be returned. If no match is found, empty string is returned. See pattern-match for a variable operation that contains additional matching capabilities.

  • test(x, pattern): Checks if string x contains the given pattern. See pattern-test for a variable operation that contains additional capabilities.

Modify Functions

  • concat(a, b, ...): Concatenates the arguments into a single string. Arguments are implicitly converted to strings.

  • replace(x, pattern, replacement): Checks string x for all substrings matching the given pattern and replaces them with the given replacement. Supports backreferences like $1, $2, …. See pattern-replace for a variable operation that contains additional capabilities.

  • lpad(x, length, c): Pads a string x to the left with the character c, so that the padded string has length characters.

  • rpad(x, length, c): Pads a string x to the right with the character c, so that the padded string has length characters.

Misc Functions

  • asc(x): Gets the ASCII character of the number x. If x is an array of numbers, gets a corresponding ASCII string.

  • ord(x) or ord(x, index): Gets the ASCII ordinal value of the first character or character at index of string x.

  • size(x): Gets the length of string x. If x is an array, gets the number of elements in the array.

Examples

startsWith(msg, 'EX')
endsWith(msg, 'EX')
contains(msg, 'error') 
match(msg, 'M\d+')
match(msg, 'M(\d+)', 1)
test(msg, 'M60(\s|$)')
replace(msg, 'M(\d+)', '$1')
asc([ch1, ch2, ch3, ch4])