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) 評論(0)  編輯  收藏 所屬分類: JAVA
          主站蜘蛛池模板: 上饶县| 石家庄市| 墨脱县| 营口市| 巴林左旗| 若尔盖县| 沂水县| 马边| 舒兰市| 云阳县| 乌拉特后旗| 大余县| 荥经县| 长武县| 比如县| 汉沽区| 额济纳旗| 宝坻区| 客服| 白银市| 固阳县| 乌审旗| 永宁县| 和田县| 凤凰县| 东光县| 四川省| 建德市| 理塘县| 翼城县| 博爱县| 克什克腾旗| 新乐市| 丽水市| 大竹县| 三江| 兴和县| 万载县| 京山县| 嘉鱼县| 马龙县|