java判断字符串String中是否存在中文


public class IsContainChinese {

  public static boolean isContainChinese (String str){

    boolean flag=true;

    int count = 0;

    String regEx = "[\\u4e00-\\u9fa5]";

    Pattern p = Pattern.compile(regEx);

    Matcher m = p.matcher(str);

    while (m.find()) {

      for (int i = 0; i <= m.groupCount(); i++) {

        count++;

      }

    }

    if(count==0){

      flag=false;

    }

    return flag;

  }

  public static void main(String[] args) {

    System.out.println(isContainChinese("我是lzhl"));

  }

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM