Created
August 2, 2012 21:25
-
-
Save frankhale/3240804 to your computer and use it in GitHub Desktop.
Strip HTML using HtmlAgilityPack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! See my fork for an even easier solution!
https://gist.github.com/starquake/8d72f1e55c0176d8240ed336f92116e3