原文:http://www.open-open.com/code/view/1426332240717

 

判断字符串中是否含有汉字:

    String str = "test中文汉字";  
    String regEx = "[//u4e00-//u9fa5]";  
      
    /** 
    * 判断有没有中文 
    */  
    if (str.getBytes().length == str.length()) {  
        System.out.println("无汉字");  
    } else {  
        System.out.println("有汉字");  
    }  
      
    /** 
    * 如果有则打印出来 
    */  
    Pattern p = Pattern.compile(regEx);  
    Matcher m = p.matcher(str);  
    while (m.find()) {  
        System.out.print(m.group(0) + "");  
    } 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-08
  • 2021-12-29
  • 2021-10-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2022-12-23
  • 2021-10-31
  • 2022-12-23
相关资源
相似解决方案