Mendix 7 is no longer supported unless you have Extended Support (for details, please contact Mendix Support). Mendix 7 documentation will remain available for customers with Extended Support until July, 2024.
String Function Calls
1 Introduction
These are functions 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'
.
2 toLowerCase
Converts all characters in the string to lowercase.
2.1 Input Parameters
- String to convert
- Type: string
2.2 Output
Same string, only all lowercase.
|
|
returns:
|
|
3 toUpperCase
Converts all characters in the string to uppercase.
3.1 Input Parameters
- String to convert
- Type: string
3.2 Output
Same string, only all uppercase.
|
|
returns:
|
|
4 length
Determines the length of a string.
4.1 Input Parameters
- A string
- Type: string
4.2 Output
- Length of the string
- Type: integer
|
|
returns:
|
|
5 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
.
5.1 Input Parameters
- Subject
- Type: string
- Start position of the substring
- Type: integer
- Desired length of the result (optional)
- Type: integer
5.2 Output
A part of the original string, starting at the start position with a length equal to the desired length. It will return a sub-string starting at the start position and ending at the end of the string.
- Type: string
|
|
returns:
|
|
If a third parameter is given, it will limit the returned number of characters to that amount:
|
|
returns:
|
|
If this third parameter is too big, the function will throw an error saying it is out of range. 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))
6 find
Finds the position of the first occurrence of the substring in the string.
6.1 Input Parameters
- Original string, the string that you want to search in
- Type: string
- Substring that you want to search for
- Type: string
- Start location to begin the search from (optional)
- Type: integer
6.2 Output
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.
- Type: integer
|
|
returns:
|
|
Substring that doesn’t occur in the original string:
|
|
returns:
|
|
With the third parameter:
|
|
returns:
|
|
7 findLast
Finds the position of the last occurrence of a substring in the original string.
7.1 Input Parameters
- Original string, the string that you want to search in
- Type: string
- Substring that you want to search for
- Type: string
- Last location to be searched (optional)
- Type: integer
7.2 Output
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.
- Type: Integer
|
|
returns:
|
|
Substring that doesn’t occur in the original string:
|
|
returns:
|
|
With the third parameter:
|
|
returns:
|
|
8 contains
Determines whether the original string (first parameter) contains a substring (second parameter).
This expression:
|
|
is equivalent to the following expression:
|
|
Searching for an empty variable or empty string, like this expression where $param = ''
:
|
|
will return true.
8.1 Input Parameters
- Original string, the string that you want to search in
- Type: string
- Substring that you want to search for
- Type: string
8.2 Output
Whether the original string contains the substring.
- Type: Boolean
|
|
returns:
|
|
9 startsWith
Determines whether a string starts with the specified substring.
9.1 Input Parameters
- Original string, the string that you want to search in
- Type: string
- Substring that you want to search for
- Type: string
9.2 Output
Whether the original string starts with the substring.
- Type: Boolean
|
|
returns:
|
|
10 endsWith
Determines whether a string ends with the specified substring.
10.1 Input Parameters
- Original string, the string that you want to search in
- Type: string
- Substring that you want to search for
- Type: string
10.2 Output
Whether the original string ends with the substring.
- Type: Boolean
|
|
returns:
|
|
11 trim
Removes all the whitespace at the beginning and end of a string.
11.1 Input Parameters
- A string
- Type: string
11.2 Output
Same string but without spaces at the beginning and end.
- Type: string
|
|
returns:
|
|
12 isMatch
Checks to see if a string matches a given regular expression.
12.1 Input Parameters
- String to try and match
- Type: string
- Regular expression to match
- Type: string
Please note that this function call uses a regular expression language provided by the current platform:
- When used inside a microflow – Java’s regular expressions (for details, see Class Pattern documentation)
- When used inside conditional formatting – JavaScript’s regular expressions (for details, see Regular Expressions documentation)
12.2 Output
Whether the string matches or not.
- Type: Boolean
This examples tests to see whether the string contains only numbers
|
|
returns:
|
|
In isMatch()
, the regex is implicitly anchored at ^
and $
.
For example:
isMatch('NLG 123.45', '[0-9]')
returns falseisMatch('NLG 123.45', '.*[0-9].*')
returns true
NB searching an empty string:
isMatch('', '.*[0-9].*')
returns false
13 replaceAll
Replaces all occurrences of a regular expression with another string.
13.1 Input Parameters
- The string to search in
- Type: string
- The regular expression to match
- Type: string
- The replacement value
- Type: string
Please note that this function call uses a regular expression language provided by the current platform:
- When used inside microflows – Java’s regular expressions (for details, see Class Pattern)
- When used inside conditional formatting – JavaScript’s regular expressions (for details, see Regular Expressions)
13.2 Output
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.
- Type: string
|
|
returns:
|
|
no matches:
|
|
returns:
|
|
14 replaceFirst
Replaces the first occurrence of the regular expression with a replacement string.
14.1 Input Parameters
- The string to search in
- Type: string
- The regular expression to match
- Type: string
- The replacement value
- Type: string
Please note that this function call uses a regular expression language provided by the current platform:
- When used inside a microflow – Java’s regular expressions (for details, see Class Pattern documentation)
- When used inside conditional formatting – JavaScript’s regular expressions (for details, see Regular Expressions documentation)
14.2 Output
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.
- Type: string
|
|
returns:
|
|
15 String Concatenation ( + )
The +
operator can be used to concatenate two strings or a string and a number.
15.1 Input Parameters
- First parameter
- Type: string, integer/long, float, or decimal
- Second parameter
- Type: string, integer/long, float, or decimal
At least one of the parameters must be of type string.
15.2 Output
A new string that is the literal concatenation of the two input parameters.
- Type: string
To combine two strings:
|
|
returns:
|
|
To combine a string and a number:
|
|
returns:
|
|
16 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:
|
|
16.1 Input Parameters
- String to convert
- Type: string
16.2 Output
The string, URL-encoded.
|
|
returns:
|
|
17 urlDecode
Converts a string back from a URL. The opposite of urlEncode.
17.1 Input Parameters
- A URL-encoded string to convert
- Type: string
17.2 Output
The string, URL-decoded.
|
|
returns:
|
|