Function: text.split

Splits the source string into a list of all substrings between each instance of the separator.

The separator itself is excluded from the substrings. In the case of overlapping instances of the separator, the leftmost match is considered. For example, text.split("baaab", "aa") returns ["b", "ab"].

Empty substrings are included in the list. This can happen when:

  • A separator is found at the beginning of the string.

    For example, text.split("abc", "a") returns ["", "bc"].

  • A separator is found at the end of the string.

    For example, text.split("abc", "c") returns ["ab", ""].

  • There are consecutive instances of the separator.

    For example, text.split("abbc", "b") returns ["a", "", "c"].

If the separator is not found, then a list containing only the source string is returned.

Arguments

Arguments
source

string

The string that will be split.

separator

string

The separator used to split the string.

Returns

A list of substrings in source.

Raised exceptions

Exceptions
TypeError If either source or separator is not a string.
ValueError If separator is an empty string or is not UTF-8 encoded.