【问题标题】:Number to UTF-8 char数字转 UTF-8 字符
【发布时间】:2019-06-20 06:36:44
【问题描述】:

在 Node.js 中,我可以向控制台打印这样的日文字符:

console.log('\u3041');

如果我有 3041 作为数字,例如因为它是随机生成的,我该如何打印相应的 UTF-8 sigil?

const charNumber = 3041;

// of course this doesn't work, but I need something like that:
console.log(`\u${charNumber}`); 

【问题讨论】:

    标签: javascript node.js utf-8


    【解决方案1】:

    您可以通过将\u 替换为0x 来使用带有.fromCharCode 的十六进制表示:

    const charNumber = 3041;
    console.log(String.fromCharCode(`0x${charNumber}`));

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-03
      • 2011-06-25
      • 1970-01-01
      • 2015-06-05
      • 1970-01-01
      • 2012-09-22
      相关资源
      最近更新 更多