简体   繁体   中英

Correct string encoding in NodeJS

I have the following string in 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);
});

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