断裂和非断裂空间ASCII字符之间的区别
我在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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
普通(断裂)空间和非断裂空间之间的区别在于,文本显示和排版软件不应插入自动线路断开以代替非破坏空间。 (好像非破裂的空间将其前后的单词加入了一个无法命名的单词。)相比之下,普通空间被视为折断线路的可能位置。
话虽如此,代码
160
实际上超出了常规(7位)ASCII的范围。160
作为非破坏空间(或nbsp
)字符的解释来自Latin1(ISO8859-1)字符集。 (在扩展ASCII中,nbsp
字符的代码为255
!!):
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 of160
as a non-breaking space (orNBSP
) character comes from the Latin1 (ISO8859-1) character set. (In Extended ASCII, the code for theNBSP
character is255
!)References:
非破坏空间是不会闯入新线路的空间。
由非破裂空间隔开的两个单词将粘在一起而不会闯入新线路。
另一方面,破裂空间将破裂。
A non-breaking space is a space that will not break into a new line.
Two words separated by a non-breaking space will stick together and not break into a new line.
Breaking spaces on the other hand will break.
有趣的事实:在空间上运行的SQL函数(例如,Ltrim())仅在断裂空间而不是在非断裂空间上运行。为了让他们处理您的角色字符串(例如,如果您导入某人使用了非破坏空间的数据),则需要先将其转换为断路空间。
Fun fact: SQL functions that operate on spaces (for example, LTRIM()) only operate on breaking spaces, not on non-breaking spaces. To get them to work on your character strings (say, for example, if you imported data where someone had used non-breaking spaces), you need to convert them to breaking spaces first.