liusheng
2024-01-19 c20e9a5dc79a642a1d59a3b4b98c9742fa58125b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.ruoyi.common.utils;
 
public class ChineseUtils {
 
    /**
     * 校验是否是中文
     *
     * @param str
     * @return
     */
    public static boolean isChinese(String str) {
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (isChineseCharacter(c)) {
                return true;
            }
        }
        return false;
    }
 
    private static boolean isChineseCharacter(char c) {
        // 汉字的Unicode编码范围是0x4E00到0x9FA5
        return c >= 0x4E00 && c <= 0x9FA5;
    }
 
}