Last active
November 19, 2019 09:24
-
-
Save LaughingVzr/f1e28bdbbf04807c20e840c0525246c7 to your computer and use it in GitHub Desktop.
[Java判断字符是否是汉字]汉字判断 #java #character util
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* CharacterUtils | |
* | |
* @author Laughing | |
* @date 2018/7/11 15:24 | |
* Description: | |
*/ | |
public class CharacterUtils { | |
/** | |
* 判断一个字符是否是中文 | |
* | |
* @param c | |
* @return | |
*/ | |
public static boolean isChinese(char c) { | |
// 根据字节码判断 | |
return c >= 0x4E00 && c <= 0x9FA5; | |
} | |
/** | |
* 判断一个字符串是否含有中文 | |
* | |
* @param str | |
* @return | |
*/ | |
public static boolean isChineseStr(String str) { | |
if (str == null) { | |
return false; | |
} | |
for (char c : str.toCharArray()) { | |
// 有一个中文字符就返回 | |
if (isChinese(c)) { | |
return true; | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment