Java String with Chinese word

Description

Java String with Chinese word


public class Main {
    public static void main(String[] argv) throws Exception {
        String chineseStr = "\u0001";
        System.out.println(isChineseCharacter(chineseStr));
    }/*from   w  ww . j ava2 s.c  o m*/

    public static final boolean isChineseCharacter(String chineseStr) {
        char[] charArray = chineseStr.toCharArray();
        for (int i = 0; i < charArray.length; i++) {
            if ((charArray[i] >= '\u0000' && charArray[i] < '\uFFFD')
                    || ((charArray[i] > '\uFFFD' && charArray[i] < '\uFFFF'))) {
                continue;
            } else {
                return false;
            }
        }
        return true;
    }
}
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] argv) throws Exception {
        String str = "\u4e01";
        System.out.println(isChinese(str));
    }/*from  w  ww . j a  v  a  2s.c  om*/

    public static Boolean isChinese(String str) {
        String regex = "^[\\u4e00-\\u9fa5]*$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(str);
        return m.matches();
    }
}



PreviousNext

Related