trim() is probably the CF function I have used the most throughout my career. Today, this trusted and straightforward function behaved in the most unexpected way: it didn’t trim the string!
Now, the string I was attempting to trim was passed in from a textarea and had been pasted in from a spreadsheet cell and… IT DEFINITELY HAD A TRAILING SPACE! And this is the weirdest bit: when I ran the code in Firefox, the string ended up trimmed but in IE, the string still had the trailing space… ??!!!?
I even tried a regular expression (
REReplace( string, "[[:space:]]+”, “”, “ALL” )) to remove all spaces but that didn’t remove the trailing space either.
I eventually found out that the problem was due to the trailing space being a non-breakable space (ascii 160). This special breed of white space must be immune to trims and excluded from the
:space: family, which I suppose actually makes sense (“non-breakable” kind of means “non-removable”).
The fact that the space had been removed when using Firefox must mean that Mozilla browsers send non-breakable spaces as regular spaces.