2010-12-10 217 views

回答

5

你必須逃脫它...如果你使用的是常規的字符串必須用雙斜線"hello\\world",或者如果你想讓它作爲文字可以使用@"hello\world"

3

是的,只需將\更改爲\\即可。

您可以閱讀更多關於轉義序列here

1

像其他人指出,使用雙斜槓「\\」

或者你可以改變你的字符串,字符串文本,而不必更新您的斜線......

string a = @"some s\tring wi\th slashes"; 
1

或者,您可以用@作爲字符串的前綴,這會告訴編譯器逐字地解釋字符串。

string str = @"i am using \ in a string"; 
3

以上所有答案都是正確的。我想要包含一個更好的方法,即使用unicode字符。 例如所述\ u005c表示「\」

因此「你好\ u005c世界」;會給輸出hello \ world

下面所有的都會給出相同的結果

string test1 = "hello \\ world"; 
string test2 = @"hello \ world"; 
string test3 = "hello \u005c world"; 

對Unicode字符集的訪問列表this site

感謝

+0

你可能是指「因此」,而不是'今後'。 – blizpasta 2010-12-10 05:42:51