问题
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.
回答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"
回答2:
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.
来源:https://stackoverflow.com/questions/38697983/difference-between-breaking-and-non-breaking-space-ascii-characters