posts - 73,  comments - 55,  trackbacks - 0
          //對于gb2312來講, 首字節碼位從0×81 至0×FE,尾字節碼位分別是0×40 至0×FE
          //本例是驗證此串是否含有gb2312格式的字符,即是否含有漢字
          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";//結果為true
          ??? String s = "ssssss";//結果為false
          ??? Test test = new Test();
          ??? System.out.println(test.isGB2312(s));
          ? }
          }
          posted on 2006-06-01 14:47 保爾任 閱讀(331) 評論(0)  編輯  收藏

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


          網站導航:
           

          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿(4)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 黄龙县| 长阳| 青浦区| 凉山| 阿拉尔市| 腾冲县| 勃利县| 龙海市| 万源市| 大英县| 东兰县| 阿鲁科尔沁旗| 大埔区| 阿克苏市| 台东县| 历史| 色达县| 九龙坡区| 大方县| 仙居县| 西宁市| 绥宁县| 齐河县| 临沂市| 乌兰县| 连城县| 乌鲁木齐县| 吐鲁番市| 宁阳县| 二连浩特市| 建水县| 乌兰察布市| 黄平县| 额敏县| 天镇县| 洞口县| 平南县| 图木舒克市| 吴江市| 全椒县| 阳原县|