微信昵称中的特殊字符的过滤

2014-10-16 | By Jinyang | Filed in: 技术相关.

/***
* 微信的昵称中特殊字符的过滤
* ***/
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:

发表评论

电子邮件地址不会被公开。 必填项已用*标注