3

Possible Duplicate:
How to add doublequotes to a string that is inside a variable?

I am trying to assign a double inverted comma to string in c# as below

string abc = " " ";

that generate error i also tried like

string abc = " +"+ ";

it also generates error please help me to solve this thing

Community
  • 1
  • 1
Mer Hardik
  • 804
  • 4
  • 14
  • 26

10 Answers10

13

Escape the " inside your string literal with a backslash

string abc = " \" ";

If you want to use a 'verbatim' string literal then you can use a double quote to escape a double quote (Strings in C#):

string abc = @" "" ";
Habib
  • 212,447
  • 27
  • 392
  • 421
4

escape it with \

string abc = " \" ";
John Woo
  • 249,283
  • 65
  • 481
  • 481
3
string blah = "\"";

escape the double quote with a backslash

Steve
  • 20,091
  • 5
  • 39
  • 64
3

Consider using a \ to escape the " character.

string abc = "\"";
Ralph Shillington
  • 20,123
  • 21
  • 92
  • 151
2

Escape it like that:

string abc = " \" ";
Lukior
  • 79
  • 3
2

You can use
string commaString= "\"";
in your snippet.Now
string newString="myString"+commaString<br/>
would be your new string
another and easiest way that c# introduced is string testString = @" "" " You should also try this
I think you need to study the escape sequence handling in c#
also see this question

Community
  • 1
  • 1
Freak
  • 6,721
  • 5
  • 35
  • 51
1

Try the following:

string abc = "\"";

The \ character tells the C# compiler to just use the next character as a normal character, not a special one (eg: double quotes, which the C# compiler thinks is a string).

matthewr
  • 4,539
  • 5
  • 28
  • 38
1

Assign like this

String abc="'"abc"'"; string abc="'"+abc+"'";

MahaSwetha
  • 1,038
  • 1
  • 12
  • 21
1

Either

 string abc = " \" ";

this is like in C or Java. Quote symbol is escaped by backslash.

Or in C# specific way:

string abc = @" "" ";

Quote symbol is typed twice.

Dims
  • 42,427
  • 94
  • 291
  • 543
0

You can use quotation marks in your string like as follows..

string abc = " \" ";

Adeel Ahmed
  • 1,541
  • 8
  • 10