String

◷ Reading Time: 9 minutes

split

Splits a string into substrings that are based on the characters in an array.

 split (value, splitter, trim, remove, minimumCount)
  • value (string): a value to be split (Mandatory)
  • splitter (string, array): splitter char, string or an array of multiple splitter (Mandatory)
  • trim (bool): true to trim each item in the split list (default true)
  • remove (bool): true to remove the empty items from a split list (default true)
  • minimumCount (number): if the split count result is less, will add a null item to match the count (default -1, does not add null values)
Example: split ('Split this sentence into words', ' ')

Result: [
     "Split",
     "this",
     "sentence",
     "into",
     "words"
 ]
Example: split ('Split this sentence into words', ' ', true, true, 7)

Result: [
     "Split",
     "this",
     "sentence",
     "into",
     "words",
     null,
     null
 ] 

substring

Retrieves a substring from a string value.

 substring (value, index, length)
  • value (string): a value to be used as source (Mandatory)
  • index (string): The zero-based starting character position of a substring in this instance
  • length (int): The number of characters in the substring (default 0)
Example: substring ('Substring this sentence', 0, 3)
Result: Sub
Example: substring ('01234', 3)
Result: 34

asString

Converts a value to its string representation.

Function version of monad asString.

 asString (value, quote)
  • value (string): a value to be used as source (Mandatory)
  • quote (bool): whether to surround the output with single quotation marks (Optional)
Example: asString (1234)
Result: 1234
Example: asString (1234, true)
Result: '1234'

format

Formatting a string template based on a Native complex value.

 format (template, value)
  • template (string): a string template (Mandatory)
  • value: a native complex value to provide values for the parameters of the template (Mandatory)
Example: format ('this is a {ADJ} test', {ADJ: 'good'})
Result: this is a good test
Example: format ('today is {todayDate}.', {todayDate: today()})
Result: today is 1/12/2020 12:00:00 AM.

join

Concatenates the elements of specified members of a collection/array, using the specified separator between each member. The output is a string.

 join (separator, members)
  • separator (string): The string to use as a separator. Separator is included in the returned string only if values have more than one element (Mandatory)
  • members (list): list of members to concatenate (Mandatory)
Example: join (',', [1,2,3])
Result: 1,2,3
Example: join (' ', ['Sam','Smith'])
Result: Sam Smith

concat

Concatenates the elements of specified members of a collection/array without any separator between each member.

 concat (members)
  • members: list of members to concatenate (Mandatory)
Example: concat (1, 2, 3, 4, 5)
Result: 12345
Example: concat ('Sam','Smith')
Result: SamSmith

trim

Removes all leading and trailing white-space characters (or specified ones) from the current string.

 trim (stringValue, characters)
  • stringValue (string): the string value to trim (Mandatory)
  • characters: list of characters to be used for trim in a left to right order. Using the characters cannot be provided.
Example: trim ('   This is a sentence.  ')
Result: This is a sentence.

toLower

Returns a copy of this string converted to lowercase.

value |toLower ()
  • value (string): the value to be converted to lowercase (Mandatory)
Example: 'HELLO'|toLower ()
Result: hello
Example: 'HeLlo'|toLower ()
Result: hello
Example: 'HeLlo123'|toLower ()
Result: hello123

toUpper

Returns a copy of this string converted to uppercase.

value |toUpper ()
  • value (string): the value to be converted to uppercase (Mandatory)
Example: 'hello'|toUpper ()
Result: HELLO
Example: 'HeLlo'|toUpper ()
Result: HELLO
Example: 'hELlo123'|toUpper ()
Result: HELLO123

startsWith

Determines whether the beginning of this string instance matches a specified string.

value |startsWith (startingString)
  • startingString (string): the starting string to match with (Mandatory)
  • value (string) : value to be checked (Mandatory)
Example: 'hello world'|startsWith ('hello')
Result: True
Example: 'hello world'|startsWith ('world')
Result: False
Example: 'hello world'|startsWith ('h')
Result: False

(The complete string should match, not just a character)

endsWith

Determines whether the end of this string instance matches a specified string.

value |endsWith (endingString)
  • endingString (string): the ending string to match with (Mandatory)
  • value (string) : value to be checked (Mandatory)
Example: 'hello world'|endsWith ('world')
Result: True
Example: 'hello world'|endsWith ('hello')
Result: False
Example: 'hello world'|endsWith ('d')
Result: False

(The complete string should match, not just a character)

Regex

Executes regular expressions patterns on a string value.

regex

Determines whether a string matches a specific regular expression pattern. It returns a boolean value.

 regex (input, pattern, flags)
  • input (string): Input string to check. If it is not a string, it will return false (Mandatory)
  • pattern (string): regex pattern (Mandatory)
  • flags: (Optional)
    • i: Specifies case-insensitive matching.
    • m: Multiline mode. Changes the meaning of ^ and $ so these respectively match at the beginning and end of any line, and not just the beginning and end of the entire string.
    • s: Specifies single-line mode. Changes the meaning of the dot (.), so that it matches every character (instead of every character except \n).

Match an email address.

Example: regex ('test@gmail.com', '\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*', 'i') 
Result: True

Match any characters including -_.,# and alphanumeric.

Example: regex ('##test-_123',  "^[-_.,#\\w]+$" , 'i') 
Result: True

Match any number.

Example: regex ('123',  "^[0-9]*$" , 'i') 
Result: True

regexMatches

Finds all the string matches based on a specific regular expression pattern.

 regex (input, pattern, groupName, flags)
  • input (string): Input string to check. If it is not a string, it will return false (Mandatory)
  • pattern (string): regex pattern (Mandatory)
  • groupName: Required. The name of regex group to list the values. The groupName must start with $ if a group name is not defined, the index can be used and must still starts with $.
  • flags: Optional
    • i: Specifies case-insensitive matching.
    • m: Multiline mode. Changes the meaning of ^ and $ so these respectively match at the beginning and end of any line, and not just the beginning and end of the entire string.
    • s: Specifies single-line mode. Changes the meaning of the dot (.), so that it matches every character (instead of every character except \n).
Example: regexMatches ('A subject with [m1] [m2]', '(\\[(.*?)\\])', '$2', 'ic')
Result: m1, m2 

regexMatch

Similar to regexMatches but this finds the first string match based on a specific regular expression pattern.

 regexMatch (input, pattern, groupName, flags)
  • input (string): Input string to check. If it is not a string, it will return false (Mandatory)
  • pattern (string): regex pattern (Mandatory)
  • groupName: Required. The name of regex group to list the values. The groupName must start with $ if a group name is not defined, the index can be used and must still starts with $.
  • flags: Optional
    • i: Specifies case-insensitive matching.
    • m: Multiline mode. Changes the meaning of ^ and $ so these respectively match at the beginning and end of any line, and not just the beginning and end of the entire string.
    • s: Specifies single-line mode. Changes the meaning of the dot (.), so that it matches every character (instead of every character except \n).
Example: regexMatches ('A subject with [m1] [m2]', '(\\[(.*?)\\])', '$2', 'ic')
Result: m1

match

Determines whether a string matches a specific regular expression pattern.

value |match (pattern, flags)
  • value (string): Input string to check. If it is not a string, it will return false (Mandatory)
  • pattern (string): regex pattern (Mandatory)
  • flags: Optional
    • i: Specifies case-insensitive matching.
    • m: Multiline mode. Changes the meaning of ^ and $ so these respectively match at the beginning and end of any line, and not just the beginning and end of the entire string.
    • s: Specifies single-line mode. Changes the meaning of the dot (.), so that it matches every character (instead of every character except \n).
    • c: Specifies that cultural differences in language are ignored.
    • r: Specifies that the search will be from right to left, instead of from left to right.
Example: "test@gmail.com" |match ("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*","i") 
Result: True

replace

Determines whether a string matches a specific regular expression pattern.

value |replace (pattern, replacement, flags)
  • pattern (string): Required
  • replacement: New string for the replacement
  • flags: Optional
    • i: Specifies case-insensitive matching.
    • m: Multiline mode. Changes the meaning of ^ and $ so these respectively match at the beginning and end of any line, and not just the beginning and end of the entire string.
    • s: Specifies single-line mode. Changes the meaning of the dot (.), so that it matches every character (instead of every character except \n).
    • c: Specifies that cultural differences in language are ignored.
    • r: Specifies that the search will be from right to left, instead of from left to right.
  • value: Required

You can also use a regex pattern as follows:

Example: "23.452,3"|replace("\\.","")
Result: 23452,3 
Example: "Your email is test@gmail.com. This should be unique"|replace("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*","<your email>")
Result: Your email is <your email>. This should be unique

Updated on December 3, 2020

Was this article helpful?

Related Articles