解析html最主要的就是利用正则表达式解析w3c中的html标签
public class HtmlHelper
{
public static string ReplaceHtmlTag(string html, int length = 0)
{
string strText = System.Text.RegularExpressions.Regex.Replace(html, "<[^>]+>", "");//替换html标签
strText = System.Text.RegularExpressions.Regex.Replace(strText, "&[^;]+;", "");//替换>\<等特殊标签
if (length > 0 && strText.Length > length)
return strText.Substring(0, length);
strText = strText.Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "");//去除换行符、制表符、空格
return strText;
}
}