In a project, I display a string that hold “E2 80 AF”:
U+202F or e2 80 af or
The page google returns to me do not explai what it is excepted UTF8 encoded value.
More research report “NARROW NO-BREAK SPACE" (https://codepoints.net).
So, I will replace it with an ASCII 32 (standard space); I already replace #160 ( ) with a standard space, so what is another line of code ?
And they call it “progress”!
Why are you replacing it?
Because it is invisible when displayed in a HTMLLViewer / Browser, where it is meant to be seen (reading a large file size with all digits stick together is… bad.
12 123 256 Bytes: I can read that;
12123256 Bytes means nothing for me.
For nearly same reason, I replace the Non Breaking Space ( ) with a standard space ( )… when displaying files names on string.
Why do I have that character in my files names is totally unknow to me (most of the time).
Where do you get this text from? Anything that is supplied to you by others can contain rubbish so you have to santise first, then process. There are plenty of standards for e.g. email content but this does not prevent e.g. microsoft Outlook from lying to you.
FWIW, the reason you are having display problems is that browsers display spaces and non-breaking spaces differently.
Spaces get coalesced. That is, if you have a run of spaces, they only show as one space. It’s a leftover from the dawn of the internet when people were translating the printed world and the designers didn’t want people to have to be so careful about spaces, not considering that such an assumption would be impossible to change later on IIRC.
Non-breaking spaces don’t coalesce. Every one that is inserted is displayed on screen.
Now… the tricky part is that all of this is just about pure HTML. It’s important to remember that adding CSS into the mix can change these behaviors.
These text comes from file names.
I wrote these file names directly in the Finder (either with an i5 or M1 MacBookPro.
And I have surprises here and then…
No later than today, I selected 50 folders from the same window (folders I created with the Finder and named them theree), but for some reason, I selected them from the Latest (xyz 59) to the First (XYZ, the second was xyz01), pasted the whole in Apple’s TextEdit and get the list reversed ( from 59 to 1, then the unnumbered)… Not a problem, only a surprise.
The text my project generate is only … pure html. Must I say “simple html” ?
File size: 12 345 678 Bytes
folowed by a “traditional” Table of Contents:
<dt><b>Table of Contents:</b><br>
Now, if I cannot do what I want, I will stay with what I get…
Now, I remember why I replace nbsp with a standard space: it is because I have to Sort the files (so I can display the Table of Content sequencially) based on the file name (1, 2, 3 instead of any other order) and for unknow reason, some files have a nbsp instead of a standard space, but not all. This is a different matter, but it all started from there (the idea to replace a character with the standard one).