posts - 73,  comments - 55,  trackbacks - 0
          //對于gb2312來講, 首字節(jié)碼位從0×81 至0×FE,尾字節(jié)碼位分別是0×40 至0×FE
          //本例是驗證此串是否含有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-06-01 14:47 保爾任 閱讀(325) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           

          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          常用鏈接

          留言簿(4)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 金华市| 涡阳县| 舞钢市| 田阳县| 长治市| 南靖县| 潜江市| 丹江口市| 甘孜县| 华坪县| 宝鸡市| 冕宁县| 德阳市| 莲花县| 尉氏县| 齐齐哈尔市| 平阴县| 阿拉善左旗| 三江| 临沧市| 东乡| 米易县| 锡林浩特市| 中宁县| 会昌县| 江口县| 平乡县| 茌平县| 甘洛县| 沧州市| 武夷山市| 若尔盖县| 柳河县| 濉溪县| 广宁县| 门源| 美姑县| 博爱县| 柘荣县| 元氏县| 伽师县|