在Java中,中文字符转换为整型数值的范围在[19968,40623) 区间内,所以我们可以采用如下方法来判断一个字符是否是中文:
public class Test {
public static void main(String args[]) {
String str = "Test 中文";
for (int i = 0; i < str.length(); i++) {
int c = (int) str.charAt(i);
if (c >= 19968 && c < 40623) {// 中文
// TO DO
System.out.println("第"+(i+1)+"个字符是中文");
}
}
}
}