Check if a character is Traditional Chinese in Big-5 (Java)?

萝らか妹 提交于 2019-12-24 04:46:26

问题


I have a thermal printer, which supports only Traditional Chinese characters other than Latin. Is there any way to check, that given a CJK character in Unicode, whether it is a valid Traditional Chinese character under Big-5 encoding?

UPDATE

Here is the method I'm using to check if a String has Unicode CJK.

public static boolean isChineseText(String s) {
    for (int i = 0; s != null && s.length() > 0 && i < s.length(); i++) {
        char ch = s.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)) {
            //Here, I want to check if its a Traditional Chinese character under Big-5
            return true;
        }
    }
    return false;
}

回答1:


The checks you were doing in your code (and Java itself) uses Unicode (not Big-5) encoding to encode traditional Chinese text. See this page for a conversion list between the encodings, or this site for a lookup.

There is no easy way that I know of to test that Chinese text is Traditional. You could check if the characters fall between 0xA140 and 0xF9D5 (apparently the Big 5 range from the link I gave above), but Unicode also has overlapping encoding in this range.

See also Differentiating CJK languages (Chinese, Japanese, Korean) in Android



来源:https://stackoverflow.com/questions/27414512/check-if-a-character-is-traditional-chinese-in-big-5-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!