最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Replace unicode characters with characters (Javascript) - Stack Overflow

programmeradmin1浏览0评论

Take for example the following string:

“A profile of Mr. T, the A Team’s most well known member.”

How do I use javascript replace the unicode character encodings and convert that to the following:

"A profile of Mr. T, the A Team's most well known member."

Take for example the following string:

“A profile of Mr. T, the A Team’s most well known member.”

How do I use javascript replace the unicode character encodings and convert that to the following:

"A profile of Mr. T, the A Team's most well known member."

Share Improve this question asked Jun 17, 2015 at 22:35 user2129607user2129607 1452 silver badges9 bronze badges 2
  • 2 stackoverflow./questions/5796718/html-entity-decode – adeneo Commented Jun 17, 2015 at 22:38
  • possible duplicate of What's the right way to decode a string that has special HTML entities in it? – Tom Blodget Commented Jun 18, 2015 at 16:48
Add a ment  | 

1 Answer 1

Reset to default 5

@adeneo posted an option using jQuery. Here's a relevant answer I found that doesn't use jQuery. From this answer: What's the right way to decode a string that has special HTML entities in it?

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);
    });
}
发布评论

评论列表(0)

  1. 暂无评论