C#newbie here。我試圖設置一個C#變量,如下所示。如何使用C#中的行情創建一個字符串#
string profileArg = @"/profile ""eScore"" ";
最終的結果是,我希望變量包含「eScore」
我該怎麼做之後的價值
/profile "eScore"
應該有字符串中的空間?
賽斯
C#newbie here。我試圖設置一個C#變量,如下所示。如何使用C#中的行情創建一個字符串#
string profileArg = @"/profile ""eScore"" ";
最終的結果是,我希望變量包含「eScore」
我該怎麼做之後的價值
/profile "eScore"
應該有字符串中的空間?
賽斯
你有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\" ";
反斜槓不用於在逐字字符串中轉義(@使其逐字)使用雙「」代替(如VB) – 2010-09-01 19:13:36
剛剛發現這個錯誤 – lumberjack4 2010-09-01 19:14:21
添加到其他。 。 。第一個引號前面的@
符號告訴C#不要將反斜槓\
解釋爲轉義字符。這就是爲什麼給出的示例省略了@
符號。然後你可以使用\"
來加引號。
2個選擇:
這兩個應該包含相同的字符串:
This is a test of "Quotes".
一種可能性是
string profileArg = "/profile \"eScore\" ";
對我來說這看起來比更清晰的逐字直譯
在這裏你去
String test = " /profile \"eScore\" ";
我很困惑您的問題,'串profileArg = @「/ profile」「eScore」「」;'似乎正是你想要的。 – 2010-09-01 19:15:05
也許你沒有看到尾部空格,因爲它是空白:) – digEmAll 2010-09-01 19:45:41