Expand/Shrink

split

Definition: sequence res = split(sequence source, object delimiter=' ', bool no_empty=true, integer limit=0)
Description: Split a sequence on the specified delimiter into a number of sub-sequences.

Returns a sequence, of sub-sequences of source. Any instances of delimiter are removed.
pwa/p2js: Supported. There is also a JavaScript string.split() function, which is not further documented here.
Comments: This function may be applied to a string or a complex sequence.

If no_empty is true, any zero-length sub-sequences are not added to the result sequence.
Use this when leading, trailing, and duplicated delimiters are not significant.
The default was changed from false to true in 0.8.3.

If limit is greater than 0, it specifies the maximum number of sub-sequences that will be created, otherwise there is no limit.

The use of named parameters is advised when setting no_empty and/or limit.

When dealing with strings, split is the logical counterpart to join().
Examples:
?split("one two three")                         -- {"one","two","three"}
?split("123","")                                -- {"1","2","3"}
?split(" John   Middle  Doe  ")                 -- {"John","Middle","Doe"}
?split(" John   Middle  Doe  ",no_empty:=false) -- {"","John","","","Middle","","Doe","",""}

The use of a named parameter for no_empty makes the intent much clearer.
Implementation: See builtins\psplit.e (an autoinclude) for details of the actual implementation.
See Also: split_any, split_by, split_path, join, flatten, columnize