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