C#去除HTML标签(转)

public static string ReplaceHtmlTag(string html, int length = 0)
{
    string strText = System.Text.RegularExpressions.Regex.Replace(html, "<[^>]+>", "");
    strText = System.Text.RegularExpressions.Regex.Replace(strText, "&[^;]+;", "");

    if (length > 0  && strText.Length > length)
        return strText.Substring(0, length);

    return strText;
}

  

Length参数可以根据传入值取固定长度的值。用于生成文章摘要比较方便。

posted @ 2013-07-18 16:53  放哨De老鼠  阅读(226)  评论(0编辑  收藏  举报