Click here to Skip to main content
15,905,558 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi ,

i have problem to convert our recevesms.aspx page in plain text ,because i need when we give response to keyword "BALANCE" through sms we got one error
"html head titleObject reference not set to an instance of an object./title style body font-family:"Verdana";font-weight:normal;"

thanks
Arvind
Posted
Comments
Sergey Alexandrovich Kryukov 21-Nov-11 14:35pm    
"Convert" by what action? Should the text file be downloaded, saved, presented in a Web browser window?
--SA
Arvind_singh 21-Nov-11 17:01pm    
any action we should want only aspx page show in runtime only plain text not html .i m also remove all the content of aspx source page but this give html i want only plain text ;

1 solution

If you mean remove html tags, heres some code for you:
C#
public static class HtmlRemoval
    {
        /// <summary>
        /// Remove HTML from string with Regex.
        /// </summary>
        public static string StripTagsRegex(string source)
        {
            return Regex.Replace(source, "<.*?>", string.Empty);
        }

        /// <summary>
        /// Compiled regular expression for performance.
        /// </summary>
        static Regex _htmlRegex = new Regex("<.*?>", RegexOptions.Compiled);

        /// <summary>
        /// Remove HTML from string with compiled Regex.
        /// </summary>
        public static string StripTagsRegexCompiled(string source)
        {
            return _htmlRegex.Replace(source, string.Empty);
        }

        /// <summary>
        /// Remove HTML tags from string using char array.
        /// </summary>
        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);
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900