十六进制html可以通过Javascript系统地转换为unicode吗?
Can hexadecimal html be systematically converted to unicode via Javascript?
我有以下字符串,例如:
"嗨,我正在测试一个奇怪的字符Ů,它是一个带圆圈的U "
现在我的字符串使用html代码Ů
来显示u形圆。我需要这个,但在unicode格式,即。'u016E
。有什么好的系统方法可以用普通的javascript来做到这一点吗?
如果您想将数字HTML字符引用转换为Unicode转义序列,请尝试以下操作(不适用于0xFFFF以上的代码点):
function convertCharRefs(string) {
return string
.replace(/&#('d+);/g, function(match, num) {
var hex = parseInt(num).toString(16);
while (hex.length < 4) hex = '0' + hex;
return "''u" + hex;
})
.replace(/&#x([A-Za-z0-9]+);/g, function(match, hex) {
while (hex.length < 4) hex = '0' + hex;
return "''u" + hex;
});
}
如果你只是想解码字符引用:
function decodeCharRefs(string) {
return string
.replace(/&#('d+);/g, function(match, num) {
return String.fromCodePoint(num);
})
.replace(/&#x([A-Za-z0-9]+);/g, function(match, num) {
return String.fromCodePoint(parseInt(num, 16));
});
}
两个函数都用String.replace
代替一个函数
相关文章:
- 正在将unicode转换为十六进制
- 如何将KSC5601转换为unicode
- 使用Javascript将Json中的unicode转换为HTML
- 当Python在Javascript中发送时,值将转换为UNICODE
- Javascript 将 unicode 字符串转换为“标题大小写”
- 将 FileReader.readAsBinaryString 转换为 Unicode 转义字符串
- 值 &# 到 Unicode 转换
- 在 JavaScript 确认窗口中将 Unicode 转换为字符
- 将 Unicode 转换回 JavaScript 转义
- 如何将 unicode 转换为 html 标记
- 用javascript将俄语(unicode)字符转换为英语
- 在Titanium移动应用程序中转换unicode字符
- 如何将unicode从HTML输入转换为javascript中的希腊字符
- Javascript-在Unicode字符串和ArrayBuffer之间转换
- 无法在javascript中转换unicode字符
- 将Unicode转义序列转换为符号,并转储到dom节点
- 使用javascript(泰国语)将此unicode转换为字符串
- Javascript Unicode转换和搜索
- 如何在javascript中将混合的ascii和unicode转换为字符串
- 使用位操作将Unicode转换为字符