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
          主站蜘蛛池模板: 罗甸县| 永胜县| 郧西县| 静宁县| 大洼县| 阳原县| 西藏| 安康市| 乌审旗| 山西省| 南和县| 会东县| 永胜县| 枣庄市| 大石桥市| 治多县| 合川市| 宁化县| 潞城市| 雷山县| 南靖县| 红河县| 常熟市| 随州市| 桓仁| 泰来县| 洛隆县| 平谷区| 莲花县| 曲靖市| 康乐县| 墨玉县| 阿拉善右旗| 龙海市| 灌云县| 如东县| 平陆县| 东丽区| 砚山县| 牟定县| 梓潼县|