4

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."

user2129607
  • 145
  • 2
  • 9
  • 2
    http://stackoverflow.com/questions/5796718/html-entity-decode – adeneo Jun 17 '15 at 22:38
  • possible duplicate of [What's the right way to decode a string that has special HTML entities in it?](http://stackoverflow.com/questions/7394748/whats-the-right-way-to-decode-a-string-that-has-special-html-entities-in-it) – Tom Blodget Jun 18 '15 at 16:48

1 Answers1

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);
    });
}
Community
  • 1
  • 1
user2129607
  • 145
  • 2
  • 9