判断一个字符是否是中文字符

在开发中经常需要判断一个字符是否是中文字符,下面给出判断函数,方便大家使用。

      /**
       * 判断是否为中文字符
       * @param c
       * @return
       */
      public  boolean isChinese(char c) {
          Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
          if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
                  || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
                  || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
                  || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
                  || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
                  || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
              return true;
          }
          return false;
      } 

推荐阅读更多精彩内容