Java String trim has no effect

You should assign the result of trim back to the String variable. Otherwise it is not going to work, because strings in Java are immutable.

String orig = "    quick brown fox    ";
String trimmed = original.trim();

The source code of that website shows the special html character  . Try searching or replacing the following in your java String: \u00A0.

That's a non-breakable space. See: I have a string with "\u00a0", and I need to replace it with "" str_replace fails

rank = rank.replaceAll("\u00A0", "");

should work. Maybe add a double \\ instead of the \.


The character is a non-breaking space, and is thus not removed by the trim() method. Iterate through the characters and print the int value of each one, to know which character you must replace by an empty string to get what you want.