java中判断是否是汉字

 

private boolean isChinese(char c) {
  String regEx = "[\u4e00-\u9fa5]";
  Pattern p = Pattern.compile(regEx);
  Matcher m = p.matcher(c + "");
  if (m.find())
   return true;
  return false;
 }

 

 

private void getCharater(int position) {
  String c = "中国人abc";
  int index = -1;
  int now = 0;
  for (int i = 0; i < c.length(); i++) {
   now = i;
   if (isChinese(c.charAt(i))) {
    if (++index == position)
     break;
    if (++index == position)
     break;
   } else {
    if (++index == position)
     break;
   }
  }
  System.out.println(c.charAt(now));
 }

 

 

 

你可能感兴趣的:(java中判断是否是汉字)