我在javascript中有两个相同的字符串,带有一些空格。 当我使用str.charCodeAt(n)打印ascii值时,它显示的值为32和160.我搜索了值,它显示为破坏和非破坏空格。 那么任何人都可以解释这种行为是什么。
I have two identical strings in javascript with some spaces. When I printed the ascii values by using str.charCodeAt(n) it is showing the values as 32 and 160. I googled the values and it is showing me as breaking and non breaking spaces. So can anybody explain what is this behaviour.
最满意答案
正常(断开)空间和不间断空间之间的区别在于文本显示和排版软件不应插入自动换行符代替不间断空格。 (就好像不间断的空间将它之前和之后的单词连接成一个不可分割的单词。)相比之下,常规空间被视为打破一条线的可能位置。
话虽如此,代码160实际上在常规(7位)ASCII范围之外。 将160解释为非中断空格(或NBSP )字符来自Latin1(ISO8859-1)字符集。 (在扩展ASCII中, NBSP字符的代码是255 !)
参考文献:
“不间断的空间” (维基百科) ASCII和扩展ASCII代码图表 “拉丁语-1(ISO8859-1)字符集”The difference between a normal (breaking) space and a non-breaking space is that text display and typesetting software should not insert an automatic line break in place of a non-breaking space. (It is as if the non-breaking space joins the words before and after it into an unsplittable word.) By contrast, a regular space is treated as a possible place to break a line.
Having said that, the code 160 is actually outside of the range of regular (7-bit) ASCII. The interpretation of 160 as a non-breaking space (or NBSP) character comes from the Latin1 (ISO8859-1) character set. (In Extended ASCII, the code for the NBSP character is 255!)
References:
"Non-breaking space" (Wikipedia) ASCII and Extended ASCII code charts "The Latin-1 (ISO8859-1) Character Set"更多推荐
发布评论