如何在C#中创建带引号的字符串

Set*_*man 6 .net c# string variables

C#newbie here.我试图设置一个C#变量如下.

string profileArg = @"/profile ""eScore"" ";
Run Code Online (Sandbox Code Playgroud)

最终结果是我希望变量包含值

/profile "eScore" 
Run Code Online (Sandbox Code Playgroud)

"eScore"之后字符串中应该有一个空格

我该怎么做?

赛斯

小智 13

你似乎已经正确地这样做了.


jga*_*fin 13

您在字符串中的eScore之后有空格.

// 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\"";
Run Code Online (Sandbox Code Playgroud)