use*_*607 3 javascript unicode unicode-string
以下面的字符串为例:
“A profile of Mr. T, the A Team’s most well known member.”
如何使用 javascript 替换 unicode 字符编码并将其转换为以下内容:
"A profile of Mr. T, the A Team's most well known member."
@adeneo 发布了一个使用 jQuery 的选项。这是我发现的一个不使用 jQuery 的相关答案。从这个答案:解码包含特殊 HTML 实体的字符串的正确方法是什么?
function parseHtmlEnteties(str) {
return str.replace(/&#([0-9]{1,4});/gi, function(match, numStr) {
var num = parseInt(numStr, 10); // read num as normal number
return String.fromCharCode(num);
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4294 次 |
| 最近记录: |