简体   繁体   English

String Unicode从字符串中删除char

[英]String Unicode remove char from the string

I have a string formatted with NumberFormat instance. 我有一个使用NumberFormat实例格式化的字符串。 When i display the chars of the string i have a non-breaking space (hexa code : A0 and unicode 160). 当我显示字符串的字符时,我有一个不间断的空格(hexa代码:A0和unicode 160)。 How can i remove this character from my string. 如何从字符串中删除此字符。 I tried string = string.replaceAll("\Š", ""); 我试过string = string.replaceAll("\Š", ""); and string = string.replaceAll("0xA0", "") , both didn't work. string = string.replaceAll("0xA0", "") ,两者都不起作用。

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. 输出仍包含十进制值160和代码点160的空白区域。

The unicode character is not a non-breaking space. unicode字符不是一个不间断的空间。 After the \\u there must be the hexadecimal representation of the character not the decimal, so the unicode for non-breaking space is . 在\\ u之后必须有十进制表示的字符而不是十进制,所以不间断空格的unicode是 Try using: 尝试使用:

string = string.replace("\u00A0","");
String string = "89774lf&933 k880990";

string = string.replaceAll( "[^\\d]", "" );

System.out.println(string);

OUTPUT: OUTPUT:

89774933880990

It will eliminate all the char other than digits . 它将消除除digits之外的所有char

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM