c# – Escape double quotes in a string

c# – Escape double quotes in a string

No.

Either use verbatim string literals as you have, or escape the using backslash.

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

The string has not changed in either case – there is a single escaped in it. This is just a way to tell C# that the character is part of the string and not a string terminator.

You can use backslash either way:

string str = He said to me, Hello World. How are you?;

It prints:

He said to me, Hello World. How are you?

which is exactly the same that is printed with:

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

Here is a DEMO.

is still part of your string.

You can check Jon Skeets Strings in C# and .NET article for more information.

c# – Escape double quotes in a string

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 other characters

   nul 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

Any character substitution by numbers:

  xh to xhhhh, or uhhhh - Unicode character in hexadecimal notation (x has variable digits, u has 4 digits)
  Uhhhhhhhh - Unicode surrogate pair (8 hex digits, 2 characters)

Leave a Reply

Your email address will not be published.