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

2014-10-16 by Jinyang | Filed under 技术相关.

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

发表评论

您的电子邮箱不会被公开。 标记为 * 的区域必须填写

返回顶部