简体   繁体   中英

Convert escaped html ASCII codes to plain text using JavaScript

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.

要将字符串中的所有数字字符实体转换为其等效字符,您可以执行以下操作:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM