/***
* 微信的昵称中特殊字符的过滤
* ***/
public static String wxNickName(String str) {
// TODO Auto-generated method stub
String ret = “”;
try {
byte[] utf8Bytes = str.getBytes(“UTF-8”);
ret = new String(utf8Bytes, “UTF-8”);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Pattern unicodeOutliers = Pattern.compile(“[^\\x00-\\x7F]”,
Pattern.UNICODE_CASE | Pattern.CANON_EQ
| Pattern.CASE_INSENSITIVE);
Matcher unicodeOutlierMatcher = unicodeOutliers.matcher(ret);
//System.out.println(“Before: ” + ret);
ret = unicodeOutlierMatcher.replaceAll(” “);
//System.out.println(“After: ” + ret);
return ret;
}
Tags: 微信
发表评论