get Char Count for mixed Chinese character and english - Android Internationalization

Android examples for Internationalization:Chinese

Description

get Char Count for mixed Chinese character and english

Demo Code


public class Main{

    public static int getCharCount(String text) {
        String Reg = "^[\u4e00-\u9fa5]{1}$";
        int result = 0;
        for (int i = 0; i < text.length(); i++) {
            String b = Character.toString(text.charAt(i));
            if (b.matches(Reg))
                result += 2;//from w  w w.j a  v  a2  s  . com
            else
                result++;
        }
        return result;
    }

}

Related Tutorials