我是一名 C# 新手。我想按如下方式设置一个 C# 变量。
string profileArg = @"/profile ""eScore"" ";
最终的结果是我希望变量包含这个值。
/profile "eScore"
"eScore"后面的字符串需要加上一个空格。
我该怎么做?
Seth
你的字符串中,在 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\"";
您似乎已经做得很正确了。
string profileArg = "/profile \"eScore\" ";
string profileArg = "/profile \"eScore\" ";
2个选项:
这两个选项应该包含相同的字符串:
This is a test of "Quotes".
一个可能性是
string profileArg = "/profile \"eScore\" ";
对我来说,这比逐字逐句的文字更清晰
试试这个:
string profileArg = "/profile \"eScore\" ";
你想为任何双引号文字加上\"
。
@
符号,可以告诉C#不要将反斜杠\
解释为转义字符。这就是为什么给出的示例省略了@
符号的原因。然后你可以使用\"
来插入引号。给你
String test = " /profile \"eScore\" ";
string profileArg = @"/profile ""eScore"" ";
似乎正是你想要的。 - Bertrand Marron