[英]Converting Unicode escapes in a string to their respective characters in JavaScript
I have the following string: 我有以下字符串:
trouble&\u0442\u0435\u0441\u0442
and would like to replace the escaped characters by their actual characters, like this: 并希望将转义字符替换为其实际字符,如下所示:
trouble&тест
How can I do so in JavaScript? 如何在JavaScript中这样做?
You can do it with the normalize
method https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize 您可以使用
normalize
方法https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize来实现
https://jsfiddle.net/fyo0y863/ https://jsfiddle.net/fyo0y863/
You can read more about Unicode in this excellent article :) https://dmitripavlutin.com/what-every-javascript-developer-should-know-about-unicode/ 您可以在这篇出色的文章中了解有关Unicode的更多信息:) https://dmitripavlutin.com/what-every-javascript-developer-should-know-about-unicode/
EDIT: As pointed out in two comments the string is already ok. 编辑:如在两个注释中指出,该字符串已经可以了。 Anyway, the link to Dmitri Pavlutin's blog is a good place to improve our comprehension of Unicode :)
无论如何,指向Dmitri Pavlutin博客的链接是提高我们对Unicode理解的好地方:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.