diff --git a/USE_CASES.md b/USE_CASES.md index eab7e74fb..60fdd79eb 100644 --- a/USE_CASES.md +++ b/USE_CASES.md @@ -11,6 +11,7 @@ This documentation provides examples for specific use cases. Please [open an iss * [Transient Fault Handling](#transient-faults) * [How to Setup a Domain Whitelabel](#domain-whitelabel) * [How to View Email Statistics](#email-stats) +* [How to transform HTML to plain text](#html-to-plain-text) # Attachments @@ -677,3 +678,33 @@ Find more information about all of SendGrid's whitelabeling related documentatio You can find documentation for how to view your email statistics via the UI [here](https://app.sendgrid.com/statistics) and via API [here](https://github.com/sendgrid/sendgrid-csharp/blob/master/USAGE.md#stats). Alternatively, we can post events to a URL of your choice via our [Event Webhook](https://sendgrid.com/docs/API_Reference/Webhooks/event.html) about events that occur as SendGrid processes your email. + + +# How to transform HTML to plain text + +Although the HTML tags could be removed using regular expressions, the best solution is parsing the HTML code with a specific library, such as [HTMLAgilityPack](http://html-agility-pack.net/). + +The following code shows how to parse an input string with HTML code and remove all tags: + +```csharp +using HtmlAgilityPack; + +namespace Example { + + internal class Example + { + /// + /// Convert the HTML content to plain text + /// + /// The html content which is going to be converted + /// A string + public static string HtmlToPlainText(string html) + { + HtmlDocument document = new HtmlDocument(); + document.LoadHtml(html); + return document.DocumentNode == null ? string.Empty : document.DocumentNode.InnerText; + } + } +} + +``` \ No newline at end of file