public static class HtmlRemoval { /// /// Remove HTML from string with Regex. /// public static string StripTagsRegex(string source) { return Regex.Replace(source, "<.*?>", string.Empty); } /// /// Compiled regular expression for performance. /// static Regex _htmlRegex = new Regex("<.*?>", RegexOptions.Compiled); /// /// Remove HTML from string with compiled Regex. /// public static string StripTagsRegexCompiled(string source) { return _htmlRegex.Replace(source, string.Empty); } /// /// Remove HTML tags from string using char array. /// public static string StripTagsCharArray(string source) { char[] array = new char[source.Length]; int arrayIndex = 0; bool inside = false; for (int i = 0; i < source.Length; i++) { char let = source[i]; if (let == '<') { inside = true; continue; } if (let == '>') { inside = false; continue; } if (!inside) { array[arrayIndex] = let; arrayIndex++; } } return new string(array, 0, arrayIndex); } }