Escape text between xml/html tags

Monday, August 29, 2011 11:15:00 AM

I had to escape the text inside of the styling generated by AJAX HTMLEditor that was getting displayed by qTip. If I did not escape the data it would break the jQuery code if there were apostrophies or any other special characters. There may be some bugs here...

private string EscapeData(string data)

    {

        int a,b,last;

        string r=string.Empty;
        a = 0;
        last = 0;

        do
                {

            a = data.IndexOf('<', a);
                   if (a == -1)
            {

                if (string.IsNullOrEmpty(r))
                    return System.Security.SecurityElement.Escape(data);

                else
                    return r + System.Security.SecurityElement.Escape(data.Substring(last));

            }
            b = data.IndexOf('>', a);

                r += System.Security.SecurityElement.Escape(data.Substring(last, a - last)) + data.Substring(a, b - a + 1);
            last = b+1;
        }while(true);

    }

Share This Using Popular Bookmarking Services
You must sign in to this site to post comments.
Site Map | Printable View | © 2008 - 2012 NuRoN Consulting, INC | Powered by mojoPortal | HTML 5 | CSS | Original design by Andreas Viklund
Share This Using Popular Bookmarking Services