码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-07-17 15:14:58      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:tool   java   view   pattern   out   打印   compile   class   ==   

原文: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) + "");  
    } 

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

标签:tool   java   view   pattern   out   打印   compile   class   ==   

原文地址:http://www.cnblogs.com/shihaiming/p/7194211.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!