Escape double quotes in a string

后端 未结 6 2237
轮回少年
轮回少年 2020-11-22 10:35

Double quotes can be escaped like this:

string test = @\"He said to me, \"\"Hello World\"\". How are you?\";

But this involves adding chara

6条回答
  •  佛祖请我去吃肉
    2020-11-22 11:17

    In C# you can use the backslash to put special characters to your string. For example, to put ", you need to write \". There are a lot of characters that you write using the backslash: Backslash with a number:

    • \000 null
    • \010 backspace
    • \011 horizontal tab
    • \012 new line
    • \015 carriage return
    • \032 substitute
    • \042 double quote
    • \047 single quote
    • \134 backslash
    • \140 grave accent

    Backslash with othe character

    • \a Bell (alert)
    • \b Backspace
    • \f Formfeed
    • \n New line
    • \r Carriage return
    • \t Horizontal tab
    • \v Vertical tab
    • \' Single quotation mark
    • \" Double quotation mark
    • \ Backslash
    • \? Literal question mark
    • \ ooo ASCII character in octal notation
    • \x hh ASCII character in hexadecimal notation
    • \x hhhh Unicode character in hexadecimal notation if this escape sequence is used in a wide-character constant or a Unicode string literal. For example, WCHAR f = L'\x4e00' or WCHAR b[] = L"The Chinese character for one is \x4e00".

提交回复
热议问题