posts - 120,  comments - 19,  trackbacks - 0
          //對于gb2312來講, 首字節(jié)碼位從0×81 至0×FE,尾字節(jié)碼位分別是0×40 至0×FE
          //本例是驗(yàn)證此串是否含有g(shù)b2312格式的字符,即是否含有漢字
          public class Test{
          ? public boolean isGB2312( String str )
          ? {
          ??? char[] chars = str.toCharArray();
          ??? boolean isGB2312 = false;
          ??? for ( int i = 0; i < chars.length; i++ )
          ??? {
          ????? byte[] bytes = ( "" + chars[i] ).getBytes();
          ????? if ( bytes.length == 2 )
          ????? {
          ??????? int[] ints = new int[2];
          ??????? ints[0] = bytes[0] & 0xff;
          ??????? ints[1] = bytes[1] & 0xff;
          ??????? if ( ints[0] >= 0x81 && ints[0] <= 0xFE && ints[1] >= 0x40 && ints[1] <= 0xFE )
          ??????? {
          ????????? isGB2312 = true;
          ????????? break;
          ??????? }
          ????? }
          ??? }
          ??? return isGB2312;
          ? }
          ?
          ? public static void main(String[] args)
          ? {
          ??? String s = "ss您好ss";//結(jié)果為true
          ??? String s = "ssssss";//結(jié)果為false
          ??? Test test = new Test();
          ??? System.out.println(test.isGB2312(s));
          ? }
          }

          posted on 2006-08-16 16:38 阿成 閱讀(489) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 徐水县| 广南县| 财经| 德安县| 康平县| 西盟| 余干县| 福州市| 贵德县| 卓资县| 兴山县| 盐边县| 石渠县| 德格县| 两当县| 高台县| 太谷县| 麻阳| 清苑县| 织金县| 威远县| 博兴县| 新河县| 酒泉市| 临泉县| 门头沟区| 平果县| 莒南县| 阳原县| 鄢陵县| 平陆县| 工布江达县| 白水县| 玉田县| 商水县| 武胜县| 华宁县| 新源县| 马公市| 门源| 嘉义县|