2007年12月12日

判斷中文字

http://eason982.blogspot.com/2007/12/blog-post.html
boolean isTraditionalChineseCharacter(char c) {
Character.UnicodeBlock block =
Character.UnicodeBlock.of(c);

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 false;
}


try {
String s = ""+c;
return s.equals(new String(s.getBytes("MS950"), "MS950"));
} catch (java.io.UnsupportedEncodingException e) {
return false; }
}

沒有留言: