码迷,mamicode.com
首页 > Windows程序 > 详细

C#去除HTML标签

时间:2018-11-02 01:44:10      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:参数   static   class   htm   标签   ret   文章   方便   ati   

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;
}

这个方法可以实现去除html标签的功能。

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

C#去除HTML标签

标签:参数   static   class   htm   标签   ret   文章   方便   ati   

原文地址:https://www.cnblogs.com/Alex80/p/9893576.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!