我獲取用戶輸入包括Unicode字符,如的Java去除Unicode字符
\xc2d
\xa0
\xe7
\xc3\ufffdd
\xc3\ufffdd
\xc2\xa0
\xc3\xa7
\xa0\xa0
例如:
email : [email protected]\xa0\xa0
street : 123 Main St.\xc2\xa0
所需的輸出:
email : [email protected]
street : 123 Main St.
什麼是最好的方式將其移除使用Java?
更新:我嘗試以下,但似乎並沒有工作
public static void main(String args[]) throws UnsupportedEncodingException {
String s = "[email protected]\\xe9.com";
String email = "[email protected]\\xa0\\xa0";
System.out.println(s.replaceAll("\\P{Print}", ""));
System.out.println(email.replaceAll("\\P{Print}", ""));
}
輸出
[email protected]\xe9.com
[email protected]\xa0\xa0
爲什麼要刪除它們? – jtahlborn
@jtahlborn,Mongo無法序列化這些值 – daydreamer