gpt4 book ai didi

javascript - 连接 unicode 和变量

转载 作者:行者123 更新时间:2023-11-29 23:07:07 24 4
gpt4 key购买 nike

我是 React 的新手,我在显示动态 unicode 值时遇到了一些问题?

{'\u{1F680}'} become {'\u{MyVar}'}

最佳答案

String.fromCodePoint将从它的数字代码点得到你的字符,parseInt将从十六进制字符串中获取数字。

您的转换将如下所示:String.fromCodePoint(parseInt(MyVariable, 16))

工作示例:

const App = ({ unicode }) => <p> 3, 2, 1, GO ! {String.fromCodePoint(parseInt(unicode, 16))}</p>

ReactDOM.render(<App unicode='1F680'/>, document.getElementById('root'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.5.2/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.5.2/umd/react-dom.production.min.js"></script>
<div id='root'>

关于javascript - 连接 unicode 和变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54507964/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com