分类:
2008-10-28 10:15:15
public static String encoding(String src){
if (src==null)
return "";
StringBuilder result=new StringBuilder();
if (src!=null){
src=src.trim();
for (int pos=0;pos switch(src.charAt(pos)){ case '\"':result.append(""");break; case '<':result.append("<");break; case '>':result.append(">");break; case '\'':result.append("'");break; case '&':result.append("&");break; case '%':result.append("&pc;");break; case '_':result.append("&ul;");break; case '#':result.append("&shap;");break; case '?':result.append("&ques;");break; default:result.append(src.charAt(pos));break; } } } return result.toString(); } //反过滤特殊字符 public static String decoding(String src){ if (src==null) return ""; String result=src; result=result.replace(""", "\"").replace("'", "\'"); result=result.replace("<", "<").replace(">", ">"); result=result.replace("&", "&"); result=result.replace("&pc;", "%").replace("&ul", "_"); result=result.replace("&shap;", "#").replace("&ques", "?"); return result; } [1]
--------------------next---------------------