gogoend / blog

blogs, ideas, etc.
MIT License
9 stars 2 forks source link

String方法备忘录 #62

Open gogoend opened 3 years ago

gogoend commented 3 years ago

类方法

fromCharCode

从Unicode基本平面码点获取字符

String.fromCharCode(0x7005)

等效于

'\u7005'
image

如果参数大于基本平面最大码点,那么最终获得的字符的码点将会按照0x10000取余,所得字符依然限制在基本平面内,即:

String.fromCharCode(0x7005)

等效于

String.fromCharCode(0x97005)

等效于

String.fromCharCode(0x97005 % 0x10000) // 参数超过最大安全整数时将出现误差
image

fromCodePoint

从Unicode任意码点(无论是基本平面还是增补平面获取字符)

String.fromCodePoint(0x1d306)

等效于

'\u{1d306}'
image

raw

原型方法

charAt

接受index 返回位于index处的字符

charCodeAt

接受位于index处的字符的unicode码

codePointAt

接受位于index处的字符的unicode码

concat

连接多个字符

endsWith

字符串是否以给定字串结尾, 可选endPosition表示结束位置。

includes

字符串是否包含给定字串。 可选position参数表示从何处开始查找。

indexOf

字符串所包含的给定子串第一次出现的位置,若无匹配则返回 -1, 可选position参数表示从何处开始查找。

lastIndexOf

字符串所包含的给定子串最后一次出现的位置,若无匹配则返回 -1, 可选position参数表示从何处开始查找。

localeCompare

match

matchAll

padEnd

padStart

repeat

replace

replaceAll

search

split

startsWith

substr

substring

toLocaleLowerCase

toLocaleUpperCase

toLowerCase

toUpperCase

trim

trimStart

trimEnd

trimLeft

trimRight

trimStart