.Net中富文本提取文字

public static string StripHTML(string stringToStrip)
        {
            if (!string.IsNullOrEmpty(stringToStrip))
            {
                stringToStrip = Regex.Replace(stringToStrip, "</p(?:\s*)>(?:\s*)<p(?:\s*)>", "

", RegexOptions.IgnoreCase | RegexOptions.Compiled);
                stringToStrip = Regex.Replace(stringToStrip, "<br(?:\s*)/>", "
", RegexOptions.IgnoreCase | RegexOptions.Compiled);
                stringToStrip = Regex.Replace(stringToStrip, """, "''", RegexOptions.IgnoreCase | RegexOptions.Compiled);
                stringToStrip = StripHtmlXmlTags(stringToStrip);
            }
            return stringToStrip;
        }
        private static string StripHtmlXmlTags(string content)
        {
            return Regex.Replace(content, "<[^>]+>", string.Empty, RegexOptions.IgnoreCase | RegexOptions.Compiled);
        }
原文地址:https://www.cnblogs.com/MrZheng/p/14918489.html