How to check whether given text is english or chinese in android?

android

Solution

If you want to detect whether the input string contains Chinese-like character(s) (CJK), the following may help you:

public static boolean isCJK(String str){
        int length = str.length();
        for (int i = 0; i < length; i++){
            char ch = str.charAt(i);
            Character.UnicodeBlock block = Character.UnicodeBlock.of(ch);
            if (Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS.equals(block)|| 
                Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS.equals(block)|| 
                Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A.equals(block)){
                return true;
            }
        }
        return false;
    }

Problem

I am designing one android application in English and Chinese both. I want to know whether the user type English text or Chinese text?. Is there any way to check this in android?

Original source

Related problems