【java】判断是否是中文或中文标点符号

 1 /**
 2  * 判断字符是否是中文,能校验是否为中文标点符号
 3  *
 4  * @param str 待校验字符
 5  * @return 是否为中文
 6  */
 7 public static boolean isContainChinese(char str) {
 8     // 中文字
 9     Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
10     Matcher m = p.matcher(String.valueOf(str));
11     if (m.find()) {
12         return true;
13     }
14 
15     // 中文标点符号
16     p = Pattern.compile("[\uFF01]|[\uFF0C-\uFF0E]|[\uFF1A-\uFF1B]|[\uFF1F]|[\uFF08-\uFF09]|[\u3001-\u3002]|[\u3010-\u3011]|[\u201C-\u201D]|[\u2013-\u2014]|[\u2018-\u2019]|[\u2026]|[\u3008-\u300F]|[\u3014-\u3015]");
17     m = p.matcher(String.valueOf(str));
18     return m.find();
19 }

参考文章:https://www.cnblogs.com/qinxu/p/8619082.html

                  https://blog.csdn.net/COCO56/article/details/87618925

猜你喜欢

转载自www.cnblogs.com/xiaostudy/p/12658451.html
今日推荐