Split
Syntax
$input.split(separator: ",", trim: true, limit: 0)
Description
Splits an input string into a list of strings using a given separator. Every occurrence of the separator string is searched for in the input string and the character strings between the separators are returned as a list.
Parameters
| String name | Type | Type Description | Mandatory | Default |
|---|---|---|---|---|
input |
Character string | The character string to be split | Yes | |
separator |
String/regular expression | The separator to be used to split the input string. | no | "," |
trim |
Truth value | Whether to remove spaces at the beginning and end of the result entries. | no | true |
limit |
Integer | Determines the maximum number of elements in the result. At 0, the string is split as many times as possible. |
no | 0 |
Return value
Type: List of character strings
The character strings between the separators found in the input string.
Examples
Standard separator
"a, b, c".split()
Output: ["a", "b", "c"]
The list of comma-separated words from the input.
With separator
"Hello world and hello moon!".split(" ")
Output: ["Hello", "world", "and", "hello", "moon!"]
The space-separated words from the input.
With regular expression
"a --- b - c -- d".split(regex("-+"))
Output: ["a", "b", "c", "d"]
The words in the input separated by any number of minus signs.
Without trimming
"a, b, c".split(trim:false)
Output: ["a", " b", " c"]
Exactly the character strings between the separators. There is a space before each of the characters b and c.
With limit
"a, b, c".split(limit:1)
Output: ["a", "b, c"]
The character string is only separated once.