Skip to main content
Module

x/denops_std/function/mod.ts>strpart

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

The result is a String, which is part of {src}, starting from byte {start}, with the byte length {len}. When {chars} is present and TRUE then {len} is the number of characters positions (composing characters are not counted separately, thus "1" means one base character and any following composing characters). To count {start} as characters instead of bytes use strcharpart().

When bytes are selected which do not exist, this doesn't result in an error, the bytes are simply omitted. If {len} is missing, the copy continues from {start} till the end of the {src}.

strpart("abcdefg", 3, 2)    == "de"
strpart("abcdefg", -2, 4)   == "ab"
strpart("abcdefg", 5, 4)    == "fg"
strpart("abcdefg", 3)       == "defg"

Note: To get the first character, {start} must be 0. For example, to get the character under the cursor:

strpart(getline("."), col(".") - 1, 1, v:true)

Returns an empty string on error.

Can also be used as a method:

GetText()->strpart(5)

Parameters

denops: Denops
src: unknown
start: unknown
optional
len: unknown
optional
chars: unknown

Returns

Promise<string>