//过滤特殊字符
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<src.length();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;
}
过滤和反过滤特殊字符
最新推荐文章于 2021-02-12 08:56:19 发布