在Windows中将Windows-1252hex值转换为Unicode

比方说,我有一个string包含一个字符的Windows-1252hex值,我想做出适当的Unicode字符:

const asciiHex = '85' //represents hellip parseInt(asciiHex, 16) //I get 133 as expected 

我不能做String.fromCharCode现在,因为这需要Unicode代码,而不是ASCII(在unicode hellip是8230(十进制))。 有谁知道任何简单的转换?

顺便说一句,我在节点6做这个

你不提到input编码:在哪个字符编码是\x85映射到水平省略号? 原来是Windows-1252,Node.js并不是“开箱”的。

一个可以编码/解码的模块是windows-1252

将您的hex代码转换为UTF-8编码的string:

 const windows1252 = require('windows-1252'); let asciiHex = '85'; let utf8text = windows1252.decode( Buffer.from(asciiHex, 'hex').toString('binary') ); console.log( utf8text ); // outputs: …