復制代碼 代碼如下:
/// 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;
}
您可能感興趣的文章:- 利用前端HTML+CSS+JS開發(fā)簡單的TODOLIST功能(記事本)
- html+css+js實現(xiàn)canvas跟隨鼠標的小圓特效源碼
- html5以及jQuery實現(xiàn)本地圖片上傳前的預覽代碼實例講解
- js+html+css實現(xiàn)手動輪播和自動輪播
- 在HTML中使用JavaScript的兩種方法
- 如何學習html的各種標簽