【问题标题】:Correct string encoding in NodeJS在 NodeJS 中正确的字符串编码
【发布时间】:2016-02-25 10:41:45
【问题描述】:

我在 NodeJS 中有以下字符串:

'3ª Jornada: Resumen 2'

应该显示为:

'3ª Jornada: Resumen 2'

我一直在尝试将其转换为另一个

decodeURIComponent(escape(myString))

但它不起作用。

有什么想法吗?

【问题讨论】:

    标签: node.js encoding


    【解决方案1】:

    根据this代码sn-p,我终于设法做到了以下方式:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-10
      • 2016-09-30
      • 1970-01-01
      • 2023-03-12
      • 2013-04-04
      • 2012-02-26
      • 1970-01-01
      相关资源
      最近更新 更多