文章目录
- 前言
- java-查询字符串当中是否包含中文
前言
如果您觉得有用的话,记得给博主点个赞,评论,收藏一键三连啊,写作不易啊^ _ ^。
而且听说点赞的人每天的运气都不会太差,实在白嫖的话,那欢迎常来啊!!!
java-查询字符串当中是否包含中文
代码:
import org.apache.commons.lang3.StringUtils;import static java.lang.Character.UnicodeBlock.*;/** 查询字符串当中是否包含中文* */
public class text2 {private static boolean checkStringContainChinese(String checkStr){if (StringUtils.isNotBlank(checkStr)) {char[] checkChars = checkStr.toCharArray();for (int i = 0; i < checkChars.length; i++) {char checkChar = checkChars[i];if (checkStringContainChinese(checkChar)) {return true;}}}return false;}private static boolean checkStringContainChinese(char checkChar) {// TODO Auto-generated method stubCharacter.UnicodeBlock ub = Character.UnicodeBlock.of(checkChar);if (CJK_UNIFIED_IDEOGRAPHS == ub||CJK_COMPATIBILITY_IDEOGRAPHS==ub||CJK_COMPATIBILITY_FORMS == ub|| CJK_RADICALS_SUPPLEMENT == ub||CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A == ub||CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B==ub) {return true;}return false;}public static void main(String[] args) {String a = "和加快速度676";String b = "";String c = "121sdhfks";System.out.println("是否包含中文:"+checkStringContainChinese(a));System.out.println("是否包含中文:"+checkStringContainChinese(b));System.out.println("是否包含中文:"+checkStringContainChinese(c));}
}
测试: