Convert escaped html ASCII codes to plain text using JavaScript

17,243

Solution 1

Try the String.fromCharCode() function.

alert(String.fromCharCode(97));

As you can see, you'll have to strip out the ampersand and pound sign.

Best regards...

Solution 2

To convert all numerical character entities in a string to their character equivalents you can do this:

str.replace(/&#(\d+);/g, function (m, n) { return String.fromCharCode(n); })

Solution 3

Check String.fromCharCode.

Share:
17,243
Jason N. Gaylord
Author by

Jason N. Gaylord

I currently spend time during the day working for biBERK, a Berkshire Hathaway Insurance Company. In my spare time, I help plan Techbash, a developer conference in the Northeastern US.

Updated on June 05, 2022

Comments

  • Jason N. Gaylord
    Jason N. Gaylord almost 2 years

    I'm looking to convert a string of html entities specifying ASCII codes (ie: a) to the ASCII characters they represent (ie: a). I'm using a property of an object and trying to assign a value. For instance:

    object.Text("");
    

    When I pass is the string representing the entity, I get the same string back. I can't find the function to convert entities to the characters they represented.