有谁知道如何在javascript中将unicode转换为字符串。例如:
\u2211 -> Σ
\u0032 -> 2
\u222B -> ∫
我基本上希望能够在 xhtml 或 html 中显示符号。还没有决定使用哪个。
最佳答案
来自 k.ken 响应的函数:
function unicodeToChar(text) {
return text.replace(/\\u[\dA-F]{4}/gi,
function (match) {
return String.fromCharCode(parseInt(match.replace(/\\u/g, ''), 16));
});
}
获取输入字符串中的所有 unicode 字符,并将它们转换为字符。
关于javascript - 将 unicode 字符转换为字符串格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17267329/