String Function Calls

Last modified: January 15, 2024

1 Introduction

This document describes functions that are used to convert and inspect strings. Note that these functions never change the string itself, they only return a new value.

Strings are surrounded by quotes. If the string contains a quote, it should be escaped by another quote. For example: 'this isn''t funny'.

For a great deep-dive look into string functions call, check out this video:

2 toLowerCase

Converts all characters in the string to lowercase.

2.1 Input Parameters

The input parameters are described in the table below:

Value Type
String to convert String

2.2 Output

The output is described in the table below:

Value Type
The same string, but all lowercase. String

2.3 Example

If you use the following input:

toLowerCase('thisISmyString')

The output is the following:

'thisismystring'

3 toUpperCase

Converts all characters in the string to uppercase.

3.1 Input Parameters

The input parameters are described in the table below:

Value Type
String to convert String

3.2 Output

The output is described in the table below:

Value Type
The same string, but all uppercase. String

3.3 Example

If you use the following input:

toUpperCase('thisISmyString')

The output is the following:

'THISISMYSTRING'

4 substring

Retrieves a substring of a string. Note that the first character of a string is located at position 0, and the last character is located at position length(string)-1.

4.1 Input Parameters

The input parameters are described in the table below:

Value Type
Subject String
Start position of the substring Integer
Desired length of the result (optional) Integer

4.2 Output

The output is described in the table below:

Value Type
A part of the original string, starting at the start position with a length equal to the desired length. If no desired length is specified, will return a substring starting at the start position and ending at the end of the string. String

4.3 Example

If you use the following input:

substring('thisismystring', 6)

The output is the following:

'mystring'

If you use a third parameter to specify the desired length of the output:

substring('thisismystring', 6, 2)

The output is the following:

'my'

To prevent the value of the third parameter from getting out of range, you can set a limit to the third parameter, for instance, using the min and length functions:

substring('thisismystring', 0, min(length('thisismystring'), 20))

5 find

Finds the position of the first occurrence of the substring in the string.

5.1 Input Parameters

The input parameters are described in the table below:

Value Type
Original string, the string that you want to search in String
Substring that you want to search for String
Start location to begin the search from (optional) Integer

5.2 Output

The output is described in the table below:

Value Type
The first location of the substring in the original string. Will return -1 if the substring does not occur at all in the original string. Integer

5.3 Example

If you use the following input:

find('thisismystring', 'my')

The output is:

6

Substring that doesn’t occur in the original string:

find('thisismystring', 'yourstring')

returns:

-1

Another example of an input is:

find('thisismystring', 'i', 5)

The output is:

11

6 findLast

Finds the position of the last occurrence of a substring in the original string.

6.1 Input Parameters

The input parameters are described in the table below:

Value Type
Original string, the string that you want to search in String
Substring that you want to search for String
Last location to be searched (optional) Integer

6.2 Output

The output is described in the table below:

Value Type
The last location of the substring in the original string. Will return -1 if the substring does not occur at all in the original string. Integer

6.3 Example

If you use the following input:

findLast('thisismystring', 't')

The output is:

9

Another example of an input where a substring does not occur in the original string:

findLast('thisismystring', 'yourstring')

The output is:

-1

An example of an input with the third parameter:

findLast('thisismystring', 'i', 5)

The output is:

4

As the optional parameter is 5, the string gets searched up to (and including) position 5, which means searching the substring 'thisis'. The last instance of 'i' in that substring is at position 4.

7 contains

Determines whether the original string (first parameter) contains a substring (second parameter).

For example, this expression:

contains('stringtosearchin', 'stringtosearchfor')

is equivalent to the following expression:

find('stringtosearchin', 'stringtosearchfor') != -1

The example below shows searching for an empty variable or empty string, where $param = '':

contains('stringtosearchin', $param)

The input above will return true.

7.1 Input Parameters

The input parameters are described in the table below:

Value Type
Original string, the string that you want to search in String
Substring that you want to search for String

7.2 Output

The output is described in the table below:

Value Type
Whether the original string contains the substring. Boolean

7.3 Example

If you use the following input:

contains('thisismystring', 'my')

The output is:

true

8 startsWith

Determines whether a string starts with the specified substring.

8.1 Input Parameters

The input parameters are described in the table below:

Value Type
Original string, the string that you want to search in String
Substring that you want to search for String

8.2 Output

The output is described in the table below:

Value Type
Whether the original string starts with the substring. Boolean

8.3 Example

If you use the following input:

startsWith('thisismystring', 'this')

The output is:

true

9 endsWith

Determines whether a string ends with the specified substring.

9.1 Input Parameters

The input parameters are described in the table below:

Value Type
Original string, the string that you want to search in String
Substring that you want to search for String

9.2 Output

The output is described in the table below:

Value Type
Whether the original string ends with the substring. Boolean

9.3 Example

If you use the following input:

endsWith('thisismystring', 'ring')

The output is:

true

10 trim

Removes all the whitespace at the beginning and end of a string.

10.1 Input Parameters

The input parameters are described in the table below:

Value Type
A string String

10.2 Output

The output is described in the table below:

Value Type
Same string, but without spaces at the beginning and end. String

10.3 Example

If you use the following input:

trim(' this is my string     ')

The output is:

'this is my string'

If the input string is empty, it returns an empty string. So, if you use the following input and MyString in the input is empty:

trim($MyString)

The output is:

''

11 isMatch

Checks to see if a string matches a given regular expression.

11.1 Input Parameters

The input parameters are described in the table below:

Value Type
String to try and match String
Regular expression to match String

11.2 Output

The output is described in the table below:

Value Type
Whether the string matches or not. Boolean

11.3 Example

This input below tests to see whether the string contains only numbers:

isMatch('234hello6432', '([0-9]+)')

The output is:

False

In isMatch(), the regex is implicitly anchored at ^ and $. This means that isMatch() will always match the entire input string instead of a substring.

Other Examples

  • isMatch('NLG 123.45', '[0-9]') returns false
  • isMatch('NLG 123.45', '.*[0-9].*') returns true

NB searching an empty string:

  • isMatch('', '.*[0-9].*') returns false

12 replaceAll

Replaces all occurrences of a regular expression with another string.

12.1 Input Parameters

The input parameters are described in the table below:

Value Type
The string to search in String
The regular expression to match; if you want to search for a literal string, enclose it between \Q and \E (for example, \QPaul S. Mueller\E will search for the string Paul S. Mueller, without interpreting the dot as a wildcard) String
The string to be substituted for each match (this does not support backreferences, substitutions, or captures) String

12.2 Output

The output is described in the table below:

Value Type
The original string, with all occurrences of the regular expression replaced by the replacement string. If the regular expression does not occur in the string, the original is returned. String

12.3 Example

If you use the following input:

replaceAll('this is a string with 75 some numbers 234 thrown in', '([0-9])', 'NUMBER')

The output is:

'this is a string with NUMBERNUMBER some numbers NUMBERNUMBERNUMBER thrown in'

Another example of an input of the following:

replaceAll('this is a string with no numbers thrown in', '([0-9])', 'NUMBER')

And the output is that there are no matches for the input:

'this is a string with no numbers thrown in'

13 replaceFirst

Replaces the first occurrence of the regular expression with a replacement string.

13.1 Input Parameters

The input parameters are described in the table below:

Value Type
The string to search in String
The regular expression to match; if you want to search for a literal string, enclose it between \Q and \E (for example, \QPaul S. Mueller\E will search for the string Paul S. Mueller, without interpreting the dot as a wildcard) String
The string to be substituted for the first match (this does not support backreferences, substitutions, or captures) String

13.2 Output

The output is described in the table below:

Value Type
The original string, with the first occurrence of the regular expression replaced by the replacement string. If the regular expression does not occur in the string, the original is returned. String

13.3 Example

If you use the following input:

replaceFirst('this is a string with 75 some numbers 234 thrown in', '([0-9])', 'NUMBER')

The output is:

'this is a string with NUMBER5 some numbers 234 thrown in'

14 String Concatenation ( + )

The + operator can be used to concatenate two strings or a string and a number.

14.1 Input Parameters

The input parameters are described in the table below:

Value Type
First parameter String, integer/long, decimal
Second parameter String, integer/long, decimal

14.2 Output

The output is described in the table below:

Value Type
A new string that is the literal concatenation of the two input parameters. String

14.3 Example

An example of an input to combine two strings can be the following:

'foo' + 'bar'

The output is:

'foobar'

An example of an input to combine a string and a number can be the following:

4.73 + ' kilometers'

The output is:

'4.73 kilometers'

15 urlEncode

Converts a string to be used in a URL. This function is useful when you want to use the string as part of the URL.

For example:

'http://google.com/search?q=' + urlEncode($myQuery)

15.1 Input Parameters

The input parameters are described in the table below:

Value Type
String to convert String

15.2 Output

The output is described in the table below:

Value Type
The string, URL-encoded. String

15.3 Example

If you use the following input:

urlEncode('Hello, world!')

The output is:

'Hello%2C+world%21'

16 urlDecode

Converts a string back from a URL. The opposite of urlEncode.

16.1 Input Parameters

The input parameters are described in the table below:

Value Type
A URL-encoded string to convert String

16.2 Output

The output is described in the table below:

Value Type
The string, URL-decoded. String

16.3 Example

If you use the following input:

urlDecode('Hello%2C+world%21')

The output is:

'Hello, world!'