How do I create a string with Quotes in it in C#
C# newbie here. I am trying to set a C# variable as follows.
string profileArg = @"/profile ""eScore"" ";
The end result is that I want the variable to con开发者_开发百科tain the value
/profile "eScore"
There should be a space in the string after the "eScore"
How do I do it?
Seth
You have a space after eScore in your string.
// a space after "eScore"
string profileArg = @"/profile ""eScore"" ";
// no space after "eScore"
string profileArg = @"/profile ""eScore""";
// space in "eScore "
string profileArg = @"/profile ""eScore """;
// No space using escaping
string profileArg = "/profile \"eScore\"";
You appear to already be doing that correctly.
string profileArg = "/profile \"eScore\" ";
string profileArg = "/profile \"eScore\" ";
2 options:
- normal backslashed escaped: "This is a test of \"Quotes\"."
- @ string double escaped: @"This is a test of ""Quotes""."
both of these should contain the same string:
This is a test of "Quotes".
One possibility would be
string profileArg = "/profile \"eScore\" ";
To me this looks clearer than the verbatim literal
Try this:
string profileArg = "/profile \"eScore\" ";
You want to put \"
for any literal double quotes.
To add to the others . . . The @
sign that precedes the first quote tells C# to not interpret the backslash \
as an escape character. That's why the examples given omit the @
sign. Then you can use the \"
to put in the quotation marks.
here you go
String test = " /profile \"eScore\" ";
精彩评论