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 \u0160
is 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:
string = string.replace("\u00A0","");
This is working as is.
public static void main(String[] args) {
String string = "hi\u0160bye";
System.out.println(string);
string = string.replaceAll("\u0160", "");
System.out.println(string);
}
String string = "89774lf&933 k880990";
string = string.replaceAll( "[^\\d]", "" );
System.out.println(string);
OUTPUT:
89774933880990
It will eliminate all the char
other than digits
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With