JavaScript 字符规范化

发布于 2024-08-04 00:40:22 字数 277 浏览 4 评论 0原文

我正在使用 Google Translate API,如果我尝试翻译 Mc Donald's,我得到的结果是:

Mc Donald&#39;s< /strong>

如何在 JavaScript 中将 &#39; 翻译为 ' 等等是否有任何其他数字字符参考? 谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

灯下孤影 2024-08-11 00:40:22

JS 库通常有辅助 api,例如 Prototype 在 String 上有 unescapeHTML() 函数,效果非常好,请注意示例:

http://prototypejs.org/api/string/unescapeHTML

JS libraries often have helper api's for this, Prototype for example has its unescapeHTML() function on String that works perfect, notice the examples:

http://prototypejs.org/api/string/unescapeHTML

浅紫色的梦幻 2024-08-11 00:40:22

像这样的事情不应该做吗?

'Mc Donald's'.replace(/&#(\d+);/g, function(m, g) {
  return String.fromCharCode(g);
});

Shouldn't something like this do it?

'Mc Donald's'.replace(/&#(\d+);/g, function(m, g) {
  return String.fromCharCode(g);
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文