Skip to main content
Module

x/denops_std/function/mod.ts>split

📚 Standard module for denops.vim
Go to Latest
function split
import { split } from "https://deno.land/x/denops_std@v6.4.0/function/mod.ts";

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()

Parameters

denops: Denops
string: unknown
optional
pattern: unknown
optional
keepempty: unknown

Returns

Promise<unknown[]>