import { fn } from "https://deno.land/x/ddc_vim@v4.0.2/deps.ts";
const { split } = fn;
Make a List
out of {string}. When {pattern} is omitted or
empty each white-separated sequence of characters becomes an
item.
Otherwise the string is split where {pattern} matches,
removing the matched characters. 'ignorecase' is not used
here, add \c to ignore case. /\c
When the first or last item is empty it is omitted, unless the
{keepempty} argument is given and it's non-zero.
Other empty items are kept when {pattern} matches at least one
character or when {keepempty} is non-zero.
Example:
:let words = split(getline('.'), '\W\+')
To split a string in individual characters:
:for c in split(mystring, '\zs')
If you want to keep the separator you can also use '\zs' at the end of the pattern:
:echo split('abc:def:ghi', ':\zs')
['abc:', 'def:', 'ghi']
Splitting a table where the first element can be empty:
:let items = split(line, ':', 1)
The opposite function is join()
.
Can also be used as a method
:
GetString()->split()