2014-10-01 73 views
-3

我有一個像如何使用C#

<p>There was a <b>.NET</b> programmer and he stripped the <i>HTML</i> tags.</p><br> </br> 

串如何從給定的字符串中刪除這些html標籤

+3

使用HTML處理庫,如[HTML Agility Pack](http://htmlagilitypack.codeplex.com/) – crashmstr 2014-10-01 12:39:10

+2

請參閱http://stackoverflow.com/questions/19523913/remove-html-tags-from -string-including-nbsp-in-c-sharp – 2014-10-01 12:39:38

回答

3

使用Htmlagilitypack

var document = new HtmlDocument(); 
document.LoadHtml(data); 
string text= document.DocumentNode.InnerText; 
+0

感謝它的工作,謝謝rjv ...... – Suresh 2014-10-01 12:43:55

1

,你可以用它來刪除文本的HTML標籤Regex.Replace 這樣的事情會做這件事

var input = "<p>There was a <b>.NET</b> programmer and he stripped the <i>HTML</i> tags.</p><br> </br>"; 
var filtered = System.Text.RegularExpressions.Regex.Replace(input, "<.*?>", ""); 
Console.WriteLine(filtered);