Question: > 
> **Possible Duplicate:**  
> 
> [How to clean HTML tags using C#](https://stackoverflow.com/questions/1038431/how-to-clean-html-tags-using-c) 
> 
> 
> 

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

Answer: 
```
  public static string StripHTML(string htmlString)
  {

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

     return Regex.Replace(htmlString, pattern, string.Empty);
  }

```
To guarantee that no HTML tags get through, use: [`HttpServerUtility.HtmlEncode(string);`](http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.htmlencode.aspx). 

If you want *some* to get through, you can use this ["Whitelist" approach](http://refactormycode.com/codes/333-sanitize-html).

Update: There has been some vulnerabilities found in that code; as a [Developer from Fog Creek tells us](http://danlec.com/blog/hacking-stackoverflow-com-s-html-sanitizer).

(Second link includes code).