What is this INSANE space character??? (google chrome) What is this INSANE space character??? (google chrome) google-chrome google-chrome

What is this INSANE space character??? (google chrome)


When I view this page's source in Internet Explorer, or download it directly from the server and view it in a text editor, the first space character in question is formatted like this in the actual HTML:

THIS character right here... " "

Notice the   entity. That is Unicode codepoint U+00A0 NO-BREAK SPACE. Chrome is just being nice and re-formatting it as   when inspecting the HTML. But make no mistake, it is a real non-breaking space, not Unicode codepoint U+0020 SPACE like you are expecting. U+00A0 is visually displayed the same as U+0020, but they are semantically different characters.

The second space character in question is formatted like this in the actual HTML:

<p>Here's just with hitting the space key (which works fine)... <code>" "</code>.</p>

So it is Unicode codepoint U+0020 and not U+00A0. Viewing the raw hex data of this page confirms that:

screenshot showing non-breaking space

screenshot showing normal space


It turns out the two seemingly identical whitespace characters are not the same character.

Behold:

var characters = ["a", "b", "c", "d", " "];var typedSpace  = " ";var copiedSpace = " ";alert("Typed: " + characters.indexOf(typedSpace));   // -1alert("Copied: " + characters.indexOf(copiedSpace)); // 4    alert(typedSpace === copiedSpace);                   // false

JSFiddle

typedSpace.charCodeAt(0) returns 32, the &#32; classic space. Whereas copiedSpace.charCodeAt(0) returns 160, the &#160 AKA   character.

The difference between the two is that a whole bunch of &#160; repeated after one another will hold their ground and create additional space between them, whereas a whole bunch of repeated &#32; characters will squish together into one space.

For instance:

A &#160;&#160;&#160;&#160;&#160; B results in: A       B

A &#32;&#32;&#32;&#32;&#32; B results in: A B

To convert the &#160; character with a &#32; character in a string, try this:

.replace(new RegExp(String.fromCharCode(160),"g")," ");

To the people in the future like myself that had to debug this from a high level all the way down to the character codes, I salute you.


It is a non breaking space.   is the entity used to represent a non-breaking space. It is essentially a standard space, the primary difference being that a browser should not break (or wrap) a line of text at the point that this   occupies.

Most likely the character is being inserted by your HTML Editor. Could you give a more specific example in context?