Skip to content

Instantly share code, notes, and snippets.

@frankhale
Created August 2, 2012 21:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save frankhale/3240804 to your computer and use it in GitHub Desktop.
Save frankhale/3240804 to your computer and use it in GitHub Desktop.
Strip HTML using HtmlAgilityPack
public static string StripHtml(this string value)
{
HtmlDocument htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(value);
if (htmlDoc == null)
return value;
StringBuilder sanitizedString = new StringBuilder();
foreach (var node in htmlDoc.DocumentNode.ChildNodes)
sanitizedString.Append(node.InnerText);
return sanitizedString.ToString();
}
@starquake
Copy link

Hi! See my fork for an even easier solution!

https://gist.github.com/starquake/8d72f1e55c0176d8240ed336f92116e3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment