string_split(s, @optional delim = \space, include_empty = false)

Split the string s and return the parts as a list of strings.

Delim should be a character, a list of characters or a predicate that accepts a character as its sole argument.

If delim is a character, s is split at each position where delim occurs.

If delim is a list of characters, s is split at each position where one of those characters occur.

If delim is a function, it is called with each character in s as argument. If delim returns true for a character, s is split at that point and that part is added to the result list.

If include_empty is true, empty parts are also included in the result.


let s = "hello, world"
// [hello,, world]
string_split(s, \,)
// [hello,  world]

string_split(s, ^(c) char_is_eq(c, \l))
// [he, o wor, d]

s = "1;2.3,4.5;6"
string_split(s, [\;, \., \,])
// [1, 2, 3, 4, 5, 6]
string_split(s, [\;, \,])
// [1, 2.3, 4.5, 6]

Also see:


Core Module Index | Contents