Skip to content

String functions

Oswaldo Baptista Vicente Junior edited this page Oct 21, 2022 · 1 revision

Camel

Converts a string to camel case.

camel("This is-a_STRING") //result: "thisIsAString"

Concatenation

Concatenates the elements passed to as arguments into a string. The function supports concatenation of strings and numbers.

concat("{id:", 123, "}") //result: "{id:123}"

Note: String concatenation can also be achieved using the Addition operator (+), provided that all arguments are string variables or literals. For example: "a" + "b"

Ends with

Returns 1 (true) if the string received in the 1st parameter ends with the suffix specified in the 2nd parameter (case-sensitive).

endsWith("abcdef", "def") //result: 1.0

Find match

Returns the first match of the given regular expression found inside a string.

findMatch("user@domain.com", "(?<=@)[^.]+(?=\.)") //result: "domain"

Find matches

Returns a list containing all matches of the given regular expression found inside a string.

findMatches("Sample tweet #java #jep", "([#][A-z]+)") //result: ["#java", "#jep"]

Format string

Returns a formatted string according to given pattern and variable arguments.

formatString("%s=%.0f", "test", 2.0) //result: "test=2"

Left pad

Left-pads a given string to the given size with white-spaces or a custom padding string.

leftPad("123", 5)      //result: "  123"
leftPad("123", 5, "0") //result: "00123"

Note: Also achievable using the alias: lpad

Lower

Converts a text string to all lower-case letters.

lower("STRING") //result: "string"

Note: Also achievable using the alias: lcase

Matches

Returns a 1 (true) if the given string contains at least one match of the given regular expression or 0 (false) if not.

matches("user@domain.com", "(?<=@)[^.]+(?=\.)") //result: 1.0

Normalize String

Normalizes a Unicode string, replacing accents and other diacritics with ASCII characters.

normalizeString("ações") //result: "acoes"

Proper

Converts a string to proper case: the first letter in each word to upper-case, and all other letter to lower-case.

proper("good DAY!") //result: "Good Day!"

Replace

Returns a new string after replacing all occurrences of the search criteria within the original string with the replacement argument.

replace("foo-boo", "oo", "ee") //result: "fee-bee"

Replace RegEx

Returns a new string after replacing all matches of the given regular expression with the replacement argument.

replaceRegex("file1.json", "(\\.\\w+$)", "") //result: "file1"

Right pad

Right-pads a given string to the given size with white-spaces or a custom padding string.

rightPad("abc", 5)      //result: "abc  "
rightPad("abc", 5, ".") //result: "abc.."

Note: Also achievable using the alias: rpad

Split

Splits a string into a string array based on a separating string or regular expression.

split("do-re-mi", "-")            //result: ["do", "re", "mi"]
split("192.168.0.1/24", "[.\\/]") //result: ["192", "168", "0", "1", "24"]

Starts with

Returns 1 (true) if the string received in the 1st parameter starts with the prefix specified in the 2nd parameter (case-sensitive).

startsWith("abcdef", "abc") //result: 1.0

Trim

Removes leading and trailing spaces.

trim("   string   ") //result: "string"

Upper

Converts a text string to all upper-case letters.

upper("string") //result: "STRING"

Note: Also achievable using the alias: ucase