double quotations

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ant

    double quotations

    Hi, how do you output a string that will be seen with double quotatios?

    I'd like to display:

    This is my "Value".

    by doing something like:

    string op = "This is my " + " + txtbox.text.ToS tring() + ";


    Any clues would be gratefully accepted.

    Ant
  • Jon Skeet [C# MVP]

    #2
    Re: double quotations

    Ant wrote:[color=blue]
    > Hi, how do you output a string that will be seen with double quotatios?
    >
    > I'd like to display:
    >
    > This is my "Value".
    >
    > by doing something like:
    >
    > string op = "This is my " + " + txtbox.text.ToS tring() + ";
    >
    >
    > Any clues would be gratefully accepted.[/color]

    You need to escape the quotes:

    string op = "This is my \"" + txtbox.Text + "\".";

    To make things more obvious, here is something in the middle of a
    string:

    string x = "This gives a \"quoted\" example.";

    See http://www.pobox.com/~skeet/csharp/strings.html for more
    information.

    Jon

    Comment

    • Marc Gravell

      #3
      Re: double quotations

      string op = "This is my \"" + txtbox.text.ToS tring() + "\"";

      i.e. \" is the escape character for " - read up on "string escape
      characters" for more info

      Marc


      Comment

      • Clive Dixon

        #4
        Re: double quotations

        Should also be pointed out for completeness that verbatim string literals
        (prefixed with @) need "" to represent a single double quote rather than an
        escape.

        string x = @"This gives a ""quoted"" example.";



        "Ant" <Ant@discussion s.microsoft.com > wrote in message
        news:0A345FD5-AAA8-48B8-99E6-A81BCF766AAC@mi crosoft.com...[color=blue]
        > Hi, how do you output a string that will be seen with double quotatios?
        >
        > I'd like to display:
        >
        > This is my "Value".
        >
        > by doing something like:
        >
        > string op = "This is my " + " + txtbox.text.ToS tring() + ";
        >
        >
        > Any clues would be gratefully accepted.
        >
        > Ant[/color]


        Comment

        Working...