c#中,我們有時需要過濾掉字串中的部分html標籤,以下是一些簡單的html標籤過濾方法,使用的主要方式是正規表示式
publicstatic
string clearhtml(string
html)
//去除a標籤
html = regex.replace(html, @"
]*>
", ""
, regexoptions.ignorecase);
html = regex.replace(html, @"
", ""
, regexoptions.ignorecase);
//去除span標籤
html = regex.replace(html, @"
]*>
", ""
, regexoptions.ignorecase);
html = regex.replace(html, @"
", ""
, regexoptions.ignorecase);
//去除所有的樣式
html = regex.replace(html, @"
\sstyle=""([^"";]+;?)+""
", ""
, regexoptions.ignorecase);
//去除所有的html標籤
html = regex.replace(html, @"
<[^>]*>|
", ""
, regexoptions.ignorecase);
return
html;
}
去除字串中的html標籤
將html標籤轉化為空 賈世義 待轉化的字串 經過轉化的字串 public static string getstringnohtml string strhtml else string newreg aryreg 0 string stroutput strhtml.replace for in...
去掉字串中的HTML標籤 記錄
要求 去掉字串中的所有html標籤。同事提供的方法 利用別人寫好的程式實現,引入第三方jar包 jericho html 3.2.jar 工具類 去掉html標籤,得到純文字內容 param content 要處理的源,帶html標籤 return public static string getp...
字串過濾
這個我這裡自己一直用的幾個函式,下面貼出來。希望盡量不是直接要例項就去用,而不關心他本來的意義和實現思路等。加油!using system using system.collections.generic using system.text using system.text.regularexpr...