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

Last modified: April 5, 2024

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.

1
toLowerCase('thisISmyString')

returns:

1
'thisismystring'

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.

1
toUpperCase('thisISmyString')

returns:

1
'THISISMYSTRING'

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
1
length('thisismystring')

returns:

1
14

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
1
substring('thisismystring', 6)

returns:

1
'mystring'

If a third parameter is given, it will limit the returned number of characters to that amount:

1
substring('thisismystring', 6, 2)

returns:

1
'my'

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
1
find('thisismystring', 'my')

returns:

1
6

Substring that doesn’t occur in the original string:

1
find('thisismystring', 'yourstring')

returns:

1
-1

With the third parameter:

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

returns:

1
11

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
1
findLast('thisismystring', 't')

returns:

1
9

Substring that doesn’t occur in the original string:

1
findLast('thisismystring', 'yourstring')

returns:

1
-1

With the third parameter:

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

returns:

1
4

8 contains

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

This expression:

1
contains('stringtosearchin', 'stringtosearchfor')

is equivalent to the following expression:

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

Searching for an empty variable or empty string, like this expression where $param = '':

1
contains('stringtosearchin', $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
1
contains('thisismystring', 'my')

returns:

1
true

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
1
startsWith('thisismystring', 'this')

returns:

1
true

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
1
endsWith('thisismystring', 'ring')

returns:

1
true

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
1
trim(' this is my string     ')

returns:

1
'this is my string'

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

12.2 Output

Whether the string matches or not.

  • Type: Boolean

This examples tests to see whether the string contains only numbers

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

returns:

1
False

In isMatch(), the regex is implicitly anchored at ^ and $.

For example:

  • 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

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

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
1
replaceAll('this is a string with 75 some numbers 234 thrown in', '([0-9])', 'NUMBER')

returns:

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

no matches:

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

returns:

1
'this is a string with no numbers thrown in'

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

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
1
replaceFirst('this is a string with 75 some numbers 234 thrown in', '([0-9])', 'NUMBER')

returns:

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

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:

1
'foo' + 'bar'

returns:

1
'foobar'

To combine a string and a number:

1
4.73 + ' kilometers'

returns:

1
'4.73 kilometers'

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:

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

16.1 Input Parameters

  • String to convert
  • Type: string

16.2 Output

The string, URL-encoded.

1
urlEncode('Hello, world!')

returns:

1
'Hello%2C+world%21'

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.

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

returns:

1
'Hello, world!'