locked
Quotes in a string RRS feed

  • Question

  • How do you put quotes inside a string? I know it has something to do with the @ symbol
    Sunday, April 15, 2007 1:49 AM

Answers

  • string foo = "a \"quoted\" string";

    /johan/
    http://idstam.com/en
    Sunday, April 15, 2007 6:36 AM
  • Yes,

    C# defines the following character escape sequences:

    Code Snippet
      \' - single quote, needed for character literals
      \" - double quote, needed for string literals
      \\ - backslash
      \0 - Unicode character 0
      \a - Alert (character 7)
      \b - Backspace (character 8)
      \f - Form feed (character 12)
      \n - New line (character 10)
      \r - Carriage return (character 13)
      \t - Horizontal tab (character 9)
      \v - Vertical quote (character 11)
      \uxxxx - Unicode escape sequence for character with hex value xxxx
      \xn[n][n][n] - Unicode escape sequence for character with hex value nnnn (variable length version of \uxxxx)
      \Uxxxxxxxx - Unicode escape sequence for character with hex value xxxxxxxx (for generating surrogates)

     

    Thanks

    Monday, April 16, 2007 6:19 AM

All replies

  • string foo = "a \"quoted\" string";

    /johan/
    http://idstam.com/en
    Sunday, April 15, 2007 6:36 AM
  • The @ symbol before the first quote means that it is a string literal, and to ignore escape sequences.
    Sunday, April 15, 2007 7:01 AM
  • Yes,

    C# defines the following character escape sequences:

    Code Snippet
      \' - single quote, needed for character literals
      \" - double quote, needed for string literals
      \\ - backslash
      \0 - Unicode character 0
      \a - Alert (character 7)
      \b - Backspace (character 8)
      \f - Form feed (character 12)
      \n - New line (character 10)
      \r - Carriage return (character 13)
      \t - Horizontal tab (character 9)
      \v - Vertical quote (character 11)
      \uxxxx - Unicode escape sequence for character with hex value xxxx
      \xn[n][n][n] - Unicode escape sequence for character with hex value nnnn (variable length version of \uxxxx)
      \Uxxxxxxxx - Unicode escape sequence for character with hex value xxxxxxxx (for generating surrogates)

     

    Thanks

    Monday, April 16, 2007 6:19 AM