How to include quotation marks in a string

I have the line "I want to learn" C # "". How to include quotes before and after C #?

+45
c #
Aug 11 '10 at 12:10
source share
6 answers

Escape them with a backslash.

"I want to learn \"C#\"" 
+87
Aug 11 '10 at 12:11
source share

Like escaping quotes with backslashes , also see question SO 2911073 , which explains how to alternatively use double quoting in the @ -prefixed line:

 string msg = @"I want to learn ""c#"""; 
+45
Aug 11 '10 at 12:16
source share

I use:

 var value = "'Field1','Field2','Field3'".Replace("'", "\""); 

unlike equivalent

 var value = "\"Field1\",\"Field2\",\"Field3\""; 

Because the former has much less noise than the latter, which simplifies viewing typos, etc.

I use it a lot in unit tests.

+8
Feb 03 '15 at 16:41
source share
 string str = @"""Hi, "" I am programmer"; 

OUTPUT - Hello, I'm a programmer

U can refer to the '@' prefix before any line in C # .NET

+7
Oct 29 '13 at 10:04 on
source share

Use escape characters like this code:

 var message = "I want to learn \"c#\""; Console.WriteLine(message); 

will output:

I want to learn "C #"

+4
Aug 11 '10 at 12:11
source share

The code:

string myString = "Hello " + ((char)34) + " World." + ((char)34);

The output will be:

Hello World.

+1
May 21 '16 at 16:44
source share



All Articles