分类:
2008-09-11 14:33:06
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---------------------