Atom

text.split()

Splits on nonoverlapping literal separators.

Signature

text.split(value, separator)

Parameters

Text and nonempty separator text.

Returns

Array of strings including empty segments.

Behavior

Reads its input without mutation.

Errors

Empty separator or invalid input type.

Example

Atom
use text
assert(count(text.split('a,,b,', ',')) == 4)

Split on commas

Use a literal separator to divide a string into fields.

Atom
use text
fields = text.split('Ada,Lin', ',')
print(fields[0])
print(fields[1])
Output
Ada
Lin

Each item contains the text between separators.

Recognize an empty field

Two adjacent commas leave an empty item between them.

Atom
use text
fields = text.split('Ada,,Lin', ',')
print(count(fields))
print(fields[1] == '')
Output
3
true

Atom keeps the empty middle field, so later fields stay in the expected positions.