简体   繁体   English

为什么Whatsapp和Javascript返回不同长度的相同unicode字符串?

[英]Why Whatsapp & Javascript return different length of same unicode string?

The unicode string in question: 有问题的unicode字符串:

ਪਹਿਲਾਂ ਲੋਕਾਂ ਦੇ ਦਿਲਾਂ ਦਿਮਾਗ਼ਾਂ ਚੋਂ ਇਹ ਵਹਿਮ ਕੱਢੋ ਕਿ 
ਅਸੀਂ ਹਿੰਦੂ ਹਾਂ,
ਅਸੀਂ ਸਿੱਖ ਹਾਂ,
ਅਸੀਂ ਮੁਸਲਮਾਨ ਹਾਂ,
ਅਸਲੀਅਤ ਇਹ ਹੈ ਕਿ 
ਅਸੀਂ ਭੁੱਖੇ ਹਾਂ, 
ਅਸੀਂ ਬੇਰੁਜ਼ਗਾਰ ਹਾਂ, 
ਅਸੀਂ ਨਸ਼ੇੜੀ ਹਾਂ, 
ਅਸੀਂ ਲਾਚਾਰ ਹਾਂ, 
ਅਸੀਂ ਬੇਵਕੂਫ਼ ਹਾਂ, 
ਅਸੀਂ ਬੀਮਾਰ ਹਾਂ, 

Language: Punjabi 语言:旁遮普语
Format: Unicode 格式:Unicode

Problem: 问题:
Javascript reports its str.length() = 226 ; Javascript报告其str.length() = 226 ; whereas WhatsApp says 700 Characters . WhatsApp700 Characters

Javascript Code: Javascript代码:

console.log(inputStr.length);

Whatsapp Screenshot 01: Whatsapp截图01:
Fine, no error: (count at 698 or 699) 很好,没有错误:(数为698或699)

Whatsapp截屏01

Just adding a new line from mobile keyboard makes it over 700 只需从移动键盘添加一条新线就可以超过700 Whatsapp截屏02

  1. Why there is a big mismatch in string length? 为什么字符串长度存在很大的不匹配?
  2. Which number is real? 哪个号码是真的?
  3. How can I get the similar result in Javascript same as of Whatsapp result? 如何在Javascript中获得与Whatsapp结果相同的结果?
  1. This seems to be a bug with Whatsapp. 这似乎是Whatsapp的一个错误。 If you try inputting text with newlines, you will find that on the 15th line it will give the error of exceeding 700 characters, no matter what the current character count is. 如果您尝试使用换行符输入文本,您会发现在第15行,无论当前字符数是多少,它都会给出超过700个字符的错误。

    If you try to put your string without the newline character it will work and not show the 700 character exceeded message (as shown in the image attached below) 如果您尝试将字符串设置为没有换行符,则它将起作用并且不显示超过700个字符的消息(如下面附带的图像所示)

  2. The correct length is the javascript string length which is 226. 正确的长度是javascript字符串长度,即226。

Your text without newlines 你的文字没有换行符

That's probably because of the way 'length' is calculated. 这可能是因为计算了“长度”的方式。 Punjabi, like any other 'foreign' language, is based on the unicode. 与任何其他“外国”语言一样,旁遮普语基于unicode。 And unicode doesn't have a fixed length in which the character is stored. 并且unicode没有存储字符的固定长度。 The unicode character takes length anywhere from 1 byte to 4 bytes. unicode字符的长度从1个字节到4个字节不等。 So, for example, the character 'ਕਿ' appears to be single but it may take 4 bytes. 因此,例如,字符“ਕਿ”似乎是单个字符,但可能需要4个字节。

Check out this post for more details. 查看帖子了解更多详情。

暂无
暂无

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

相关问题 Javascript Unicode:相同的字母但不同的unicode - Javascript Unicode: same letters but different unicode 为什么在分隔符与字符串值相同的长度为 1 的字符串上使用 string.split() 返回长度为 2 的数组 - Why does using string.split() on a string of length one where the delimiter is the same as the string value return an array of length two 为什么此javascript函数针对同一查询返回两个不同的结果? - Why does this javascript function return two different results for the same query? 为什么输入字段中相同字符串的字符串长度和JS中变量字符串的静态值不同 - Why the string length is different for the same string in input field and as static value of variable string in JS 为什么Node crypto为同一个字符串返回不同的值? - Why does Node crypto return different values for the same string? 计算一个数组中的项目,如果实例数与另一个数组的长度相同,则返回该项目,javascript - count items in an one array, if the number of instances is the same as the length of a different array, return the item, javascript 返回字符串中最长单词的长度(JavaScript) - Return length of longest word in string (Javascript) 相同的string.length但文本的对齐方式不同 - Same string.length but different justification of text 为什么`({}+{}+{}*2).length` 在 Javascript 中返回 33? - Why does `({}+{}+{}*2).length` return 33 in Javascript? 为什么string.length返回undefined? - why string.length return undefined?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM