How To Convert Html To Plain Text C#?
Solution 1:
You can use regex expressions forthis.
Regex.Replace(htmltext, "<.*?>", string.Empty);
Eg:- String htmltext = "string html = "<p>Test1 <b>.NET</b> Test2Test3
<i>HTML</i> Test4.</p>";"Output will be :- Test1Test2Test3Test4.
This will help to you. http://www.codeproject.com/Tips/136704/Remove-all-the-HTML-tags-and-display-a-plain-text
Solution 2:
Short answer: No direct conversion; you're "screen-scraping" a website; parse the result string to extract what you need (or better yet, see if there is an API provided by the website in question).
Websites render in HTML, not plain text. Although you're getting the result back as a string, you'll need to parse it to extract the text you are interested in. The actual extraction highly depends on what you are trying to accomplish. If the website is proper XHTML, you can load it into an XDocument
as XML and traverse the tree to get the information you need; otherwise, the HTMLAgilityPack suggested in one of the comments may be of help (not as magical as the comment is alluding to - it's a bit more work than GetString
...)
Post a Comment for "How To Convert Html To Plain Text C#?"