Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Function

split — slice a string into an array of strings

Synopsis

split(s: string, sep: string) -> [string]

Description

The split function slices string s into all substrings separated by the string sep appearing in s and returns an array of the substrings spanning those separators.

Examples


Split a semi-colon delimited list of fruits

# spq
values split(this,";")
# input
"apple;banana;pear;peach"
# expected output
["apple","banana","pear","peach"]

Split a comma-separated list of IPs and cast the array of strings to an array of IPs

# spq
values cast(split(this,","),<[ip]>)
# input
"10.0.0.1,10.0.0.2,10.0.0.3"
# expected output
[10.0.0.1,10.0.0.2,10.0.0.3]