contains Chinese by unicode - Java Internationalization

Java examples for Internationalization:Chinese

Description

contains Chinese by unicode

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String str = "java2s.com";
        System.out.println(containsChinese(str));
    }//from  w w  w  . j av  a  2s .c o m

    public static final boolean containsChinese(String str) {
        if (str == null) {
            return false;
        }
        boolean hasChinese = false;
        for (int i = 0; i < str.length(); i++) {
            if (isChinese(str.charAt(i))) {
                hasChinese = true;
                break;
            }
        }
        return hasChinese;
    }

    public static final boolean isChinese(char ch) {
        return ('\u4E00' <= ch && ch <= '\u9FA5');
        //      int value = (int )ch;
        //      return (19968<=value && value<=171941);
    }
}

Related Tutorials