String Unicode removes char from string

I have a string formatted with an instance of NumberFormat. When I show the characters of a string, I have inextricable 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 did not 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 space with a decimal value of 160 and a code of 160.

+7
source share
3 answers

The Unicode character \u0160 not inextricable. After \ u, there should be a hexadecimal representation of the character, not a decimal, therefore unicode for non-breaking space \u00A0 . Try using:

 string = string.replace("\u00A0",""); 
+39
source
 String string = "89774lf&933 k880990"; string = string.replaceAll( "[^\\d]", "" ); System.out.println(string); 

OUTPUT:

 89774933880990 

It will destroy all char except digits .

+4
source

It works as it is.

 public static void main(String[] args) { String string = "hi\u0160bye"; System.out.println(string); string = string.replaceAll("\u0160", ""); System.out.println(string); } 
+1
source

All Articles