How to get only text from HTML code in ASP.NET and in C#?

How to get only text from HTML code in ASP.NET and in C#?


The third party library “HtmlAgilityPack” will give the feature to get the inner text of html code.

StringBuilder strBuilder = new StringBuilder();

            HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.LoadHtml(“<html code>”);

            foreach(HtmlAgilityPack.HtmlNode node in htmlDoc.DocumentNode.ChildNodes)
            {
                strBuilder.Append(node.InnerText);
            }

            return strBuilder.ToString();

No comments:

Post a Comment