How do I remove all HTML tags from a string without knowing which tags are in it?
c#, html
Solution
You can use a simple regex like this:
public static string StripHTML(string input)
{
return Regex.Replace(input, "<.*?>", String.Empty);
}
Be aware that this solution has its own flaw. See Remove HTML tags in String for more information (especially the comments of 'Mark E. Haase'/@mehaase)
Another solution would be to use the HTML Agility Pack. You can find an example using the library here: HTML agility pack - removing unwanted tags without removing content?
Problem
Is there any easy way to remove all HTML tags or ANYTHING HTML related from a string? For example: ``` string title = "<b> Hulk Hogan's Celebrity Championship Wrestling <font color=\"#228b22\">[Proj # 206010]</font></b> (Reality Series, )" ``` The above should really be: "Hulk Hogan's Celebrity Championship Wrestling [Proj # 206010] (Reality Series)"