Esempio n. 1
0
        public static string ParseHtmlBQ(object temp)
        {
            string html = Wf_ConvertHelper.ToString(temp);

            if (Wf_StringHelper.IsNullOrEmptyByTrim(html))
            {
                return("");
            }
            try
            {
                html = Wf_RegexHelper.ParseToHtml(html);                //替换换行 空格
                html = System.Text.RegularExpressions.Regex.Replace(html, "<!--.*?-->", "", System.Text.RegularExpressions.RegexOptions.Compiled);
                html = System.Text.RegularExpressions.Regex.Replace(html, "((<[a-z!].*?>)|(</.+?>))", "", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline);
                html = System.Text.RegularExpressions.Regex.Replace(html, @"\s+", " ", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline);
                html = System.Text.RegularExpressions.Regex.Replace(html, @"&nbsp;", " ", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline);
                return(html);
            }
            catch { return(""); }
        }
Esempio n. 2
0
        /// <summary>
        /// 去除Html标签
        /// </summary>
        /// <param name="html"><p>abcdefg</p></param>
        /// <returns>abcdefg</returns>
        public static string ParseHtml(string input)
        {
            if (Wf_StringHelper.IsNullOrEmptyByTrim(input))
            {
                return("");
            }
            try
            {
                string html = Wf_RegexHelper.ParseToHtml(input);                //替换换行 空格
                html = System.Text.RegularExpressions.Regex.Replace(html, "<!--.*?-->", "", System.Text.RegularExpressions.RegexOptions.Compiled);
                html = System.Text.RegularExpressions.Regex.Replace(html, "<style.*?>.*?</style>", "", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline);
                html = System.Text.RegularExpressions.Regex.Replace(html, "<script.*?>.*?</script>", "", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline);
                html = System.Text.RegularExpressions.Regex.Replace(html, "<head>.*?</head>", "", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline);
                html = System.Text.RegularExpressions.Regex.Replace(html, "<option.*?>.*?</option>", "", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline);
                html = System.Text.RegularExpressions.Regex.Replace(html, "((<[a-z!].*?>)|(</.+?>))", "", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline);
                html = System.Text.RegularExpressions.Regex.Replace(html, @"\s+", " ", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline);

                return(html);
            }
            catch (Exception)
            {
                return(input);
            }
        }