我想做类似的事情:
string s = "\\blabla";
当你写“\”时,这意味着只有一个'\'。如何编写字符串,以便实际上有 2 '\' 表示 "\" ?
This works without a problem:
string s = "//blabla";
If you mean the backslash instead, you can use a verbatim string literal (using the @
symbol to avoid processing escape symbols):
string s = @"\\blabla";
Alternatively you can escape the escape character itself:
string s = "\\\\blabla";
'/'
is not the escape char, so you can simply write "//"
The escape char is '\'
and, to use it properly, you can refer to the MSDN instructions.
Try this:
string s = @"\\blabla";
The '@' symbol treats whatever follows it as a verbatim string literal (ie: you won't need to worry about escape characters within the string).
I think you mean \
not /
.
You could escape the \
with another backslash "\\\\"
or you could use a string literal @"\\"
您可以在字符串之前使用 @ 以避免转义特殊字符。
@-quoting 的优点是不处理转义序列,方便编写
http://msdn.microsoft.com/en-us/library/362314fe(v=vs.71).aspx