gpt4 book ai didi

Javascript + Emoji 奇怪的东西

转载 作者:行者123 更新时间:2023-11-28 08:31:33 26 4
gpt4 key购买 nike

我正在尝试对一些嵌入了表情符号的文本执行一些字符串方法。

但是,这是我见过的一件非常奇怪的事情:

"🌑".length == 2

我只是想知道它是如何决定对我来说显示为 1 个字符的,实际上是 2 个。

最佳答案

In Javascript, a string is a sequence of 16-bit code points. Since emoji > are encoded above the BMP, it means that they are represented by a pair > of code points, also known as a surrogate pair.So for instance, 0x1F600, which is 😀, is represented by:

"\uD83D\uDE00"

如果您愿意进一步了解这一点,可以阅读这篇文章:Emojis in Javascript - Parsing emoji in Javascript is… not easy.

关于Javascript + Emoji 奇怪的东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21802329/

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