Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

i want to convert html tags to plain text
but am still having a problem with <img src="https://XXX"/> tag conversion
any suggestion please ??
Posted
Comments
Naga Sindhura 25-Apr-14 6:47am    
Hi Sarah, Please mention your requirement exactly with Expected output.

1 solution

Simply use this method hope it solves your problem:

C#
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);
        }


Call it like:
C#
string convertedString = StripTagsCharArray(strHTML); //strHTML is your string with HTML
 
Share this answer
 
Comments
Sarah MQ 25-Apr-14 7:07am    
thank you sanket saxena !! thanks a lot :)
Sanket Saxena 25-Apr-14 7:09am    
Welcome and glad to help you.

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