posts - 495,comments - 227,trackbacks - 0

           

          public static String unicodeEncode(String strText) {
                  
          char c;
                  String strRet 
          = "";
                  
          int intAsc;
                  String strHex;
                  
          for (int i = 0; i < strText.length(); i++{
                      c 
          = strText.charAt(i);
                      intAsc 
          = c;
                      
          if (intAsc > 128{
                          strHex 
          = Integer.toHexString(intAsc);
                          strRet 
          += "\\u" + strHex;
                      }
           else {
                          strRet 
          = strRet + c;
                      }

                  }

                  
          return strRet;
              }

              
              
          public static String unicodeDecode(String strText) {
                  StringBuilder sb 
          = new StringBuilder();
                  
          int i = 0;
                  
          char c;
                  
          while (i < strText.length()) {
                      c 
          = strText.charAt(i);
                      
          if (c == '\\' && (i + 1!= strText.length() && strText.charAt(i + 1== 'u'{
                          sb.append((
          char) Integer.parseInt(strText.substring(i + 2, i + 6), 16));
                          i 
          += 6;
                      }
           else {
                          sb.append(c);
                          i
          ++;
                      }

                  }

                  
          return sb.toString();
              }
          posted on 2011-04-22 13:53 SIMONE 閱讀(1302) 評論(0)  編輯  收藏 所屬分類: JAVA
          主站蜘蛛池模板: 普格县| 谷城县| 柏乡县| 随州市| 怀集县| 顺平县| 湖南省| 保亭| 武义县| 吴旗县| 新营市| 锡林浩特市| 庆城县| 新和县| 明星| 阜康市| 民勤县| 正安县| 汉寿县| 双辽市| 屏东县| 佛山市| 淮北市| 金秀| 舞阳县| 张家港市| 宁化县| 平陆县| 扶沟县| 德格县| 社会| 大余县| 泸定县| 白银市| 靖安县| 大竹县| 云南省| 泸水县| 甘孜县| 射洪县| 西峡县|