C# Code Snippet - Remove HTML Tags

C# Code Snippet - Remove HTML Tags

C# Code Snippet - Remove HTML Tags

(C-Sharp) C# code snippet to remove all HTML TAGS from a string. StripHTML strip all HTML tags from a given string and return plain text.

Bookmark:

C# Code Snippet - Remove HTML Tags

This .Net C# code snippet removes all HTML TAGS from a string. HTML stripping done by set of successful matches found by iteratively applying a regular expression pattern to the input string.

public string StripHTML(string str)
{
    return System.Text.RegularExpressions.Regex.Replace(str, @"<(.|\n)*?>", string.Empty);
}


C# Keywords Used:

  • Regex
  • Replace

Code Snippet Information:

  • Applies To: .Net, C#, CLI, HTML, Regular Expression
  • Programming Language : C#

External Resources:

Leave a comment