.Net C# remove HTML tags from a string

public static string StripHtmlTagFromString(this HtmlHelper htmlHelper, string html)
        {
            var htmlLength = new char[html.Length];
           
            var htmlIndex = 0;
            
            var inTag = false;

            foreach (var letter in html)
            {
                if (letter == '<')
                {
                    inTag = true;
                    continue;
                }

                if (letter == '>')
                {
                    inTag = false;
                    continue;
                }

                if (inTag) continue;

                htmlLength[htmlIndex] = letter;
             
                htmlIndex++;
            }

            return new string(htmlLength, 0, htmlIndex);
        }

Leave a Reply

Your email address will not be published. Required fields are marked *