Quote in string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HalilTorun
    New Member
    • Nov 2008
    • 7

    #1

    Quote in string

    There is a thread with the same name, but I could not add my question there.

    I am trying to include double quotes in a string in C#. It seems straightforward but I could not do it. The below line is taken from msdn (msdn.microsoft .com/en-us/library/aa691090(VS.71) .aspx )

    string e = "Joe said \"Hello\" to me"; // Joe said "Hello" to me
    string f = @"Joe said ""Hello"" to me"; // Joe said "Hello" to me

    e and f must have the value, Joe said "Hello" to me, (at least the comments say so) but they do not have.

    They have the value: Joe said \"Hello\" to me.

    While debugging I open the Text Visualizer, HTML Visualizer, and XML Visualizer screens for e and f strings. They all show the string's value as Joe said "Hello" to me. But in the code they do not have that value.

    Thanks for any comment,

    Halil
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Is your question why does C# have a problems with quotes? Try is to think about the string in its context, where the string would begin and end without the code modifications. Another way this is gotten around is using " instead.

    Comment

    • HalilTorun
      New Member
      • Nov 2008
      • 7

      #3
      Ok, thanks. I figured out the solution.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Originally posted by HalilTorun
        But in the code they do not have that value.
        if by that you are refering to the debug window, the debug window will show them WITH the escape comments, and not as a string literal (which would be just the " without the \)

        As I understand it VB.NET does NOT support \", but does support ""

        Comment

        Working...