简体   繁体   English

在NodeJS中正确的字符串编码

[英]Correct string encoding in NodeJS

I have the following string in NodeJS: 我在NodeJS中有以下字符串:

'3ª Jornada: Resumen 2'

which should be shown as: 应显示为:

'3ª Jornada: Resumen 2'

I have been trying to convert it to another 我一直在尝试将其转换为另一个

decodeURIComponent(escape(myString))

but it did not work. 但它没有用。

Any ideas? 有任何想法吗?

According to this code snippet, I finally managed to do it in the following way: 根据代码片段,我终于设法通过以下方式做到这一点:

myString = myString.replace(/&#(x[0-9A-Fa-f]{2});/g, function(match, hex) {
    return String.fromCharCode('0' + hex);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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