Skip to content

String 静态方法

fromCharCode()

String.fromCharCode() 静态方法返回由指定的 UTF-16 码元序列创建的字符串。

js
console.log(String.fromCharCode(189, 43, 190, 61))
// Expected output: "½+¾="

fromCodePoint()

String.fromCodePoint() 静态方法将根据指定的码位序列返回一个字符串。

js
console.log(String.fromCodePoint(9731, 9733, 9842, 0x2f804))
// Expected output: "☃★♲你"

raw()

String.raw() 静态方法是模板字符串的标签函数。它的作用类似于 Python 中的 r 前缀或 C# 中用于字符串字面量的 @ 前缀。它用于获取模板字符串的原始字符串形式——即,替换表达式(例如 ${foo})会被替换处理,但转义序列(例如 \n)不会被处理。

js
// Create a variable that uses a Windows
// path without escaping the backslashes:
const filePath = String.raw`C:\Development\profile\aboutme.html`

console.log(`The file was uploaded from: ${filePath}`)
// Expected output: "The file was uploaded from: C:\Development\profile\aboutme.html"

基于 MIT 许可发布