I'm using Google Translate API, and if I try to translate Mc Donald's this is what I get as a result:
Mc Donald's
How can I translate ' to ' -- in JavaScript -- and so on for any other numeric character reference?
Thanks!
Alyona Yavorska
5792 gold badges14 silver badges20 bronze badges
asked Sep 4, 2009 at 2:42
Andres SK
11.1k27 gold badges98 silver badges159 bronze badges
3 Answers 3
answered Sep 4, 2009 at 3:22
Havenard
28.1k5 gold badges38 silver badges66 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
JS libraries often have helper api's for this, Prototype for example has its unescapeHTML() function on String that works perfect, notice the examples:
Comments
Shouldn't something like this do it?
'Mc Donald's'.replace(/&#(\d+);/g, function(m, g) {
return String.fromCharCode(g);
});
answered Sep 4, 2009 at 3:27
kangax
39.2k13 gold badges101 silver badges135 bronze badges
Comments
lang-js