欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

去除HTML标签删除HTML示例代码

程序员文章站 2024-02-25 18:43:09
复制代码 代码如下: /// /// 去除html标签 /// ///
复制代码 代码如下:

/// <summary>
/// 去除html标签
/// </summary>
/// <param name="htmlstring"></param>
/// <returns></returns>
public static string deletehtml(string htmlstring)
{
//删除html
htmlstring = regex.replace(htmlstring, @"<(.[^>]*)>", "", regexoptions.ignorecase);
htmlstring = regex.replace(htmlstring, @"([\r\n])[\s]+", "", regexoptions.ignorecase);
htmlstring = regex.replace(htmlstring, @"-->", "", regexoptions.ignorecase);
htmlstring = regex.replace(htmlstring, @"<!--.*", "", regexoptions.ignorecase);
htmlstring = regex.replace(htmlstring, @"&(quot|#34);", "\"", regexoptions.ignorecase);
htmlstring = regex.replace(htmlstring, @"&(amp|#38);", "&", regexoptions.ignorecase);
htmlstring = regex.replace(htmlstring, @"&(lt|#60);", "<", regexoptions.ignorecase);
htmlstring = regex.replace(htmlstring, @"&(gt|#62);", ">", regexoptions.ignorecase);
htmlstring = regex.replace(htmlstring, @"&(nbsp|#160);", "", regexoptions.ignorecase);
htmlstring = regex.replace(htmlstring, @"&(iexcl|#161);", "\xa1", regexoptions.ignorecase);
htmlstring = regex.replace(htmlstring, @"&(cent|#162);", "\xa2", regexoptions.ignorecase);
htmlstring = regex.replace(htmlstring, @"&(pound|#163);", "\xa3", regexoptions.ignorecase);
htmlstring = regex.replace(htmlstring, @"&(copy|#169);", "\xa9", regexoptions.ignorecase);
htmlstring = regex.replace(htmlstring, @"(\d+);", "", regexoptions.ignorecase);
htmlstring = htmlstring.replace("<", "");
htmlstring = htmlstring.replace(">", "");
htmlstring = htmlstring.replace("\r\n", "");
return htmlstring;
}