【问题标题】:Unicode char from input does not show输入中的 Unicode 字符不显示
【发布时间】:2018-12-29 16:21:30
【问题描述】:

我正在尝试根据用户输入显示 unicode char。如果我尝试在控制台中打印它。

const emoji  = `{\\u${this.state.textInput}}`;
            console.log(emoji);
            console.log(`\u{1f40e}`)

但结果是

第一个来自输入,第二个是直接写入 unicode。谢谢

【问题讨论】:

    标签: input unicode printing emoji


    【解决方案1】:

    你可以试试:

    const emoji = String.fromCodePoint(`0x${this.state.textInput}`);
    

    如果您使用\\u 转义整个字符串,那么您会得到一个以\u 开头的字符串,而不是需要转义的Unicode 字符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-04
      • 1970-01-01
      相关资源
      最近更新 更多