简体   繁体   English

Javascript toLowerCase()使用非拉丁字符提供不同的长度

[英]Javascript toLowerCase() giving different length with non-Latin characters

Why JS has problem with capitalized i ( İ ) while javascript is ok with capitalized ş,ö,ç,ğ,ü ( Ş , Ö , Ç , Ğ , Ü ), as stated below? 为什么JS的大写字母i( İ )有问题,而javascript的大写ş,ö,ç,ğ,ü( ŞÖÇĞÜ )是可以的呢? (Problem is not related with the letter position.) (问题与字母位置无关。)

"İş".toLowerCase().length
3
"İŞ".toLowerCase().length
3
"iŞ".toLowerCase().length
2
"iş".toLowerCase().length
2

Moreover 此外

"İ".length
1
"İ".toLowerCase().length
2
"İ".toLocaleLowerCase().length
2

For sceptics, here is screen shot of console where i copied the above codes: 对于怀疑论者,这是控制台的屏幕快照,我在其中复制了上面的代码:

在此处输入图片说明

and my charset (which is the first thing I've checked after this problem occurs): 和我的字符集(发生此问题后,我检查的第一件事):

<meta charset="utf-8" />

Thanks in advance. 提前致谢。

The issue is the character above capital İ . 问题是大写İ 上方的字符。 That is another string value in javascript. 那是javascript中的另一个字符串值。 You can use .split(); 您可以使用.split(); to see the character counts. 查看字符数。 One more thing to notice it is not just about capital İ but is also in those list. 还有一点要注意它不只是资本İ也是在那些列表。

You should use String.prototype.toLocaleLowerCase() to locale-specific case mappings. 您应该使用String.prototype.toLocaleLowerCase()来进行特定于语言环境的案例映射。

 console.log("áş".toLocaleLowerCase().split('')); console.log("İş".toLocaleLowerCase().split('')); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM