Exemple #1
0
        /// <summary>
        /// Removes all HTML comments from a string.
        /// </summary>
        /// <param name="strString">The string.</param>
        /// <returns>Comment-free version of string.</returns>
        public static string RemoveComments(string strString)
        {
            // Return comment-free version of string
            string           strCommentFreeString = "";
            string           strSegment           = "";
            HTMLStringHelper parser = new HTMLStringHelper(strString);

            while (parser.ExtractTo("<!--", ref strSegment))
            {
                strCommentFreeString += strSegment;
                if (!parser.SkipToEndOf("-->"))
                {
                    return(strString);
                }
            }

            parser.ExtractToEnd(ref strSegment);
            strCommentFreeString += strSegment;
            return(strCommentFreeString);
        }
Exemple #2
0
        /// <summary>
        /// Removes all scripts from a string.
        /// </summary>
        /// <param name="strString">The string.</param>
        /// <returns>Version of string without any scripts.</returns>
        public static string RemoveScripts(string strString)
        {
            // Get script-free version of content
            string           strStringSansScripts = "";
            string           strSegment           = "";
            HTMLStringHelper parser = new HTMLStringHelper(strString);

            while (parser.ExtractToNoCase("<script", ref strSegment))
            {
                strStringSansScripts += strSegment;
                if (!parser.SkipToEndOfNoCase("</script>"))
                {
                    parser.Content = strStringSansScripts;
                    return(strString);
                }
            }

            parser.ExtractToEnd(ref strSegment);
            strStringSansScripts += strSegment;
            return(strStringSansScripts);
        }