Skip to main content
Module

x/denops_std/function/mod.ts>char2nr

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

Return Number value of the first char in {string}. Examples:

char2nr(" ")            returns 32
char2nr("ABC")          returns 65

When {utf8} is omitted or zero, the current 'encoding' is used. Example for "utf-8":

char2nr("á")            returns 225
char2nr("á"[0])         returns 195

When {utf8} is TRUE, always treat as UTF-8 characters. A combining character is a separate character. nr2char() does the opposite. To turn a string into a list of character numbers:

let str = "ABC"
let list = map(split(str, '\zs'), {_, val -> char2nr(val)})

Result: [65, 66, 67]

Returns 0 if {string} is not a String.

Can also be used as a method:

GetChar()->char2nr()

Parameters

denops: Denops
string: unknown
optional
utf8: unknown

Returns

Promise<number>