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 閱讀(1308) 評(píng)論(0)  編輯  收藏 所屬分類: JAVA
          主站蜘蛛池模板: 旅游| 贵阳市| 古田县| 喜德县| 南丹县| 阳谷县| 南雄市| 武山县| 株洲市| 赤水市| 逊克县| 宁安市| 济南市| 吉隆县| 利津县| 鹤岗市| 都安| 门头沟区| 绿春县| 咸阳市| 金门县| 津南区| 武穴市| 和龙市| 汉沽区| 乐昌市| 葵青区| 宜宾市| 彭泽县| 正蓝旗| 咸宁市| 且末县| 莱西市| 泸溪县| 永靖县| 芜湖县| 阳谷县| 济南市| 山东省| 濮阳市| 邛崃市|