Skip to main content
Module

x/denops_std/function/mod.ts>byteidx

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

Return byte index of the {nr}'th character in the String {expr}. Use zero for the first character, it then returns zero. If there are no multibyte characters the returned value is equal to {nr}. Composing characters are not counted separately, their byte length is added to the preceding base character. See byteidxcomp() below for counting composing characters separately. Example :

echo matchstr(str, ".", byteidx(str, 3))

will display the fourth character. Another way to do the same:

let s = strpart(str, byteidx(str, 3))
echo strpart(s, 0, byteidx(s, 1))

Also see strgetchar() and strcharpart().

If there are less than {nr} characters -1 is returned. If there are exactly {nr} characters the length of the string in bytes is returned.

Can also be used as a method:

GetName()->byteidx(idx)

Parameters

denops: Denops
expr: unknown
nr: unknown

Returns

Promise<number>