public static string HtmlEncode(string theString)
{
theString = theString.Replace(">", ">");
theString = theString.Replace("<", "<");
theString = theString.Replace(" ", " ");
theString = theString.Replace(" ", " ");
theString = theString.Replace("/"", """);
theString = theString.Replace("/'", "'");
theString = theString.Replace("/n", "<br/> ");
return theString;
}
public static string HtmlDiscode(string theString)
{
theString = theString.Replace(">", ">");
theString = theString.Replace("<", "<");
theString = theString.Replace(" ", " ");
theString = theString.Replace(" ", " ");
theString = theString.Replace(""", "/"");
theString = theString.Replace("'", "/'");
theString = theString.Replace("<br/> ", "/n");
return theString;
}
//用正则表达式过滤html标记的
public static string DealHtml(string str)
{
str = Regex.Replace(str, @"/<(img)[^>]*>|<//(img)>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"/<(table|tbody|tr|td|th|)[^>]*>|<//(table|tbody|tr|td|th|)>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"/<(div|blockquote|fieldset|legend)[^>]*>|<//(div|blockquote|fieldset|legend)>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"/<(font|i|u|h[1-9]|s)[^>]*>|<//(font|i|u|h[1-9]|s)>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"/<(style|strong)[^>]*>|<//(style|strong)>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"/<a[^>]*>|<//a>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"/<(meta|iframe|frame|span|tbody|layer)[^>]*>|<//(iframe|frame|meta|span|tbody|layer)>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"/<a[^>]*", "", RegexOptions.IgnoreCase);
return st
}