Strip XML - CSharp System

CSharp examples for System:String Strip

Description

Strip XML

Demo Code


using System.Text;

public class Main{
        public static string StripXML(string source)
        {/*from w ww  .  j a v  a 2 s.  co m*/
            char[] buffer = new char[source.Length];
            int bufferIndex = 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)
                {
                    buffer[bufferIndex] = let;
                    bufferIndex++;
                }
            }
            return new string(buffer, 0, bufferIndex);
        }
}

Related Tutorials