Genzotto
Genzotto

Reputation: 1974

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?

Upvotes: 0

Views: 60

Answers (1)

Genzotto
Genzotto

Reputation: 1974

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);
});

Upvotes: 1

Related Questions