I would like write a java function like: if one char is not in GB2312, return false
Boolean isGB2312(String chinese) {
......
}
I would like write a java function like: if one char is not in GB2312, return false
Boolean isGB2312(String chinese) {
......
}
I haven't used Java for a while, but I know of Iconv, which can throw an exception when there is illegal character, so you can return false when an exception is caught, and return true when the conversion to UTF-8 went through without problem.
import java.nio.charset.*;
class Some{
public static void main(String args[])
{
final Charset cs = Charset.forName("GB2312");
final CharsetEncoder encode = cs.newEncoder();
System.out.println(encode.canEncode("ダチヂッツヅテデ"));
}
}
UPDATE: As a static method:
final static boolean isGB2312(final String s)
{
return java.nio.charset.Charset.forName("GB2312").newEncoder().canEncode(s);
}