最简单之Android判断字符串是否包含中文

   
   String str="这样写会是中文";
   Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
   Matcher m = p.matcher(str);
   if (m.find()) {
           Toast.makeText(getContext(), "是中文", Toast.LENGTH_SHORT).show();
       }else {
           Toast.makeText(getContext(), "不是中文",Toast.LENGTH_SHORT).show();

   }     

猜你喜欢

转载自blog.csdn.net/weixin_42744183/article/details/87716464
今日推荐