Share via


StringBuilder - how to escape double-quotes

Question

Monday, September 26, 2011 3:39 AM

I'm putting together a custom JSON string via the StringBuilder, and ran into an odd issue with escaped double-quotes. Escaping them works, but the backslash used to escape them is included after the call 'ToString()'. I don't run into this issue with string variables. I need to get this working to reduce overhead. 

Any advice?

All replies (5)

Monday, September 26, 2011 3:59 PM âś…Answered | 1 vote

Until we dont see your example, we can onyl guess what you want to.

So here`s an exmple of using quotation marks in string and stingBuilder class:

            string a1 = "text\"some text in quotes\" next text."; //1st option
            string a2 = @"text""som text in quotes"" next text."; //2nd option

            StringBuilder sb = new StringBuilder();
            sb.AppendLine(a1);
            sb.AppendLine(a2);

            Console.WriteLine(sb.ToString());
            Console.ReadLine(); 

Mitja


Monday, September 26, 2011 3:50 AM

usually adding extra double quotes would do the trick... however, do you have sample codes to analyze?


Monday, September 26, 2011 1:46 PM

Hi,

You can use  format as in string.format. Please check out this Link:

http://msdn.microsoft.com/en-us/library/hdekwk0b.aspx

Software Developer


Monday, September 26, 2011 3:36 PM

I'm putting together a custom JSON string via the StringBuilder, and ran into an odd issue with escaped double-quotes. Escaping them works, but the backslash used to escape them is included after the call 'ToString()'. I don't run into this issue with string variables. I need to get this working to reduce overhead. 

Any advice?

Show us what you did?Mitja


Monday, September 26, 2011 3:45 PM | 1 vote

Hi Ironwill,

 

you can use replace function to remove Double quotes like this

 

            String sData= char.ConvertFromUtf32(34) + " Sample Data " + char.ConvertFromUtf32(34);
            MessageBox.Show(sData);
            sData = sData.Replace(char.ConvertFromUtf32(34) ,"");
            MessageBox.Show(sData);

Happy Coding, RDRaja