最近发现,网络实在是一个很不安全的东西。你开发的东西如果不做任何处理就把它放到网络上,那么等待你的就只有眼泪。下面是一个很简单的过滤特殊字符的函数: public string FilterSpecial(string str)//特殊字符过滤函数 { if (str == "") //如果字符串为空,直接返回。 { return str; } else { str = str.Replace("'", ""); str = str.Replace("<", ""); str = str.Replace(">", ""); str = str.Replace("%", ""); str = str.Replace("'delete", ""); str = str.Replace("''", ""); str = str.Replace("\"\"", ""); str = str.Replace(",", ""); str = str.Replace(".", ""); str = str.Replace(">=", ""); str = str.Replace("=<", ""); str = str.Replace("-", ""); str = str.Replace("_", ""); str = str.Replace(";", ""); str = str.Replace("||", ""); str = str.Replace("[", ""); str = str.Replace("]", ""); str = str.Replace("&", ""); str = str.Replace("/", ""); str = str.Replace("-", ""); str = str.Replace("|", ""); str = str.Replace("?", ""); str = str.Replace(">?", ""); str = str.Replace("?<", ""); str = str.Replace(" ", ""); return str; } } 更高效率的办法 public string UrnHtml(string strHtml) { string[] aryReg ={ "'", "<", ">", "%","\"\"", ",", ".", ">=", "=<", "-", "_", ";", "||", "[", "]", "&", "/", "-", "|"," ", }; for (int i = 0; i < aryReg.Length; i++) { strHtml = strHtml.Replace(aryReg[i], string.Empty); } return strHtml; }
www.jxgzseo.cn |