去除HTML標(biāo)簽刪除HTML示例代碼
更新時間:2014年06月04日 17:19:39 作者:
這篇文章主要介紹了如何去除HTML標(biāo)簽、刪除HTML。示例中使用到了一個正則,直接使用就可以了
復(fù)制代碼 代碼如下:
/// <summary>
/// 去除HTML標(biāo)簽
/// </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;
}
相關(guān)文章
"PageMethods未定義"或"對象不支持此屬性或方法"解決方法分享
PageMethods未定義或?qū)ο蟛恢С执藢傩曰蚍椒ń鉀Q方法,需要的朋友可以參考下。2010-12-12
ASP.NET Core擴展庫之Http通用擴展庫的使用詳解
這篇文章主要介紹了ASP.NET Core擴展庫之Http通用擴展庫的使用詳解,幫助大家更好的理解和學(xué)習(xí)使用.net技術(shù),感興趣的朋友可以了解下2021-04-04
IIS上部署你的ASP.NET?Core?Web?Api項目及Swagger(圖文)
本篇經(jīng)驗將和大家介紹如何在IIS上部署ASP.NET?Core項目,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,希望為初學(xué).NET?CORE的童靴入門有所幫助2023-09-09
google suggest 下拉菜單實現(xiàn)代碼(asp.net版本)
原來發(fā)表過,是asp版本的,但是不支持上下鍵,現(xiàn)在后臺處理程序用.net寫的。代碼進行部分優(yōu)化。2009-07-07
the sourcesafe database has been locked by the administrator
今天早上打開soucesafe的時候出現(xiàn)提示:“the sourcesafe database has been locked by the administrator"。仔細想想, 可能是前天晚上用"f:\analyze.exe" -I- -DB -F -V3 -D "f:\vssData\data" 命今分析的時候鎖定了database2009-04-04

