为什么是"i"是不是等于“i̇"? [英] Why "i" is not equals to "i̇"?

查看:79
本文介绍了为什么是"i"是不是等于“i̇"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Google chrome的JavaScript控制台中,输入以下代码:

In the javascript console of google chrome type the following code:

"i" == "i̇"

并意识到它返回false.但是他们两个都有相同的字符代码(105).

and realize that it returns false. But both of them has the same char code (105).

这怎么可能?为什么?

评论后,我意识到第二个我有2个字符,但是第二个字符是由以下代码制成的:

After comments, I realize second i has 2 characters, but second character was made from the following code:

 "İ".toLowerCase() // outputs i̇

"İ".length // returns 1

如何以及为什么javascript .toLowerCase()可以计算字符长度?

How and why javascript .toLowerCase() can count up the char length?

推荐答案

console.log("i".length, "i̇".length)
> 1 2

第二个字符串有一个额外的字符.结果为 false ,因为两个字符串不同.

The second string has an extra character. The result is false as the two strings are not the same.

如果我们使用 charCodeAt(),我们可以看到这个额外的字符是Unciode符号775,称为

If we use charCodeAt() we can see that this extra character is Unciode symbol 775, known as a combining dot above.

̇ 组合 01407 775 0x307 ̇ 上方的点

这篇关于为什么是"i"是不是等于“i̇"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆