I have a string formatted with NumberFormat instance. When i display the chars of the string i have a non-breaking space (hexa code : A0 and unicode 160). How can i remove this character from my string.
I tried string = string.replaceAll("\u0160", ""); and string = string.replaceAll("0xA0", ""), both didn’t work.
String string = ((JTextField)c)getText();
string = string.replace("\u0160", "");
System.out.println("string : " string);
for(int i = 0; i < string.length; i++) {
System.out.print("char : " + string.charAt(i));
System.out.printf("Decimal value %d", (int)string.charAt(i));
System.out.println("Code point : " + Character.codePointAt(string, i));
}
The output still contains a white space with decimal value 160 and code point 160.
The unicode character
\u0160is not a non-breaking space. After the \u there must be the hexadecimal representation of the character not the decimal, so the unicode for non-breaking space is\u00A0. Try using: