Sponsored Ad

Wednesday, April 7, 2010

How to Encode Single Quotes and Double Quotes in C#

 

encodeSingleQuotes utility will help you to convert single quotes to double quotes in given string. This is very useful while working with JavaScript and database. Because single quotes is not supported sometimes or have different meaning.

        public static string encodeSingleQuotes(string pStrValue)
        {
            string returnString = pStrValue.Replace("\'", "\'\'");
            return returnString;
        }

encodeHtmlSingleDoubleQuotes utility will help you to convert single quote and double quote to Unicode characters or encode in html supported format. This useful while passing url as query string and for database operations.

        public static string encodeHtmlSingleDoubleQuotes(string pStrHtmlValue)
        {
            string returnHtmlString = pStrHtmlValue.Replace("'", "'").Replace("\"", """);

            return returnHtmlString;
        }

No comments:

Post a Comment

Sponsored Ad

Development Updates