String.trim() bug...
In this case String.trim() returns "hello "
The character it has trouble trimming is known in HTML as& n b p s ;
Is this a bug? it certainly looks like white space if you ask me.
publicclass NoBreakTrimTest{
publicstaticvoid main(String[] args){
char c = 0x00A0;
String input ="hello" + c;
String trimmed = input.trim();
System.out.println("Trimmed: " + trimmed);
boolean equal = trimmed.equals("hello");
System.out.println("Equal: " + equal);
}
}
[981 byte] By [
jvaudrya] at [2007-11-27 8:41:01]

String.trim() only removes all spaces before and after any characters in the string.For example:
[b]Input:[/b]"nbsp;"
[b]Output:[/b]"nbsp;"
But
[b]Input:[/b]"n b s p ;"
[b]Output:[/b]"n b s p ;"
I.E , its not a bug , you have misunderstood what String.trim() does
> Err that was a joke ;-)
Not completely, no. This sort of thread has a tendency to degenerate quite quickly into a flamewar when the OP won't accept that it isn't a bug. Seems easier to just let them file a bug report and get on with other things!
> OP, if it's a bug, please show us what part of the
> specification of String.trim() is being violated.
I'd add to that, "be prepared to reverse your belief in this bug, if it is shown not to be a bug".
Hi,
I was not thinking it was a bug as in a bug Sun would fix:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4080617
Rather, I thought, this is just really weird
input.trim() // returns "hello "
It seems like trim() only works on ASCII strings. Too bad for all those suckers who need to trim Unicode strings!
According to the spec: "If this String object represents an empty character sequence, or the first and last characters of character sequence represented by this String object both have codes greater than '\u0020' (the space character), then a reference to this String object is returned."
So, it seems that it will work with Unicode strings, but no-break spaces are not considered to be in the scope of whitespace characters.
RATiXa at 2007-7-12 20:39:46 >

> String.trim() only removes all spaces before and
> after any characters in the string.For example:
Actually, as others have pointed out, it removes "white space" characters not just spaces
> I.E , its not a bug , you have misunderstood what
> String.trim() does
Ditto.
jbisha at 2007-7-12 20:39:47 >
