1 public class IsChineseOrEnglish { 2 // GENERAL_PUNCTUATION 判断中文的“号 3 // CJK_SYMBOLS_AND_PUNCTUATION 判断中文的。号 4 // HALFWIDTH_AND_FULLWIDTH_FORMS 判断中文的,号 5 public static boolean isChinese(char c) { 6 Character.UnicodeBlock ub = Character.UnicodeBlock.of(c); 7 if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS 8 || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS 9 || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A 10 || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION 11 || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION 12 || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS){ 13 return true; 14 } 15 return false; 16 } 17 public static void isChinese(String strName) { 18 char[] ch = strName.toCharArray(); 19 for (int i = 0; i < ch.length; i++) { 20 char c = ch[i]; 21 if(isChinese(c)==true){ 22 System.out.println(isChinese(c)); 23 return; 24 }else{ 25 System.out.println(isChinese(c)); 26 return ; 27 } 28 } 29 } 30 public static void main(String[] args){ 31 isChinese("zhongguo"); 32 isChinese("中国"); 33 } 34 }
时间: 2024-10-02 12:47:02