Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I strip html tags in C# [duplicate]

Tags:

html

c#

.net

Possible Duplicate:
How to clean HTML tags using C#

What is the best way to strip HTML tags in C#?

like image 689
Mr.CSharp Avatar asked Feb 25 '10 14:02

Mr.CSharp


People also ask

How do you remove HTML tags?

Approach: Select the HTML element which need to remove. Use JavaScript remove() and removeChild() method to remove the element from the HTML document.

Is it possible to remove the HTML tags from data?

Strip_tags() is a function that allows you to strip out all HTML and PHP tags from a given string (parameter one), however you can also use parameter two to specify a list of HTML tags you want.

How do I strip a string in HTML?

To strip out all the HTML tags from a string there are lots of procedures in JavaScript. In order to strip out tags we can use replace() function and can also use . textContent property, . innerText property from HTML DOM.


1 Answers

  public static string StripHTML(string htmlString)
  {

     string pattern = @"<(.|\n)*?>";

     return Regex.Replace(htmlString, pattern, string.Empty);
  }
like image 115
Ivan G. Avatar answered Sep 21 '22 15:09

Ivan G.