[英]Weird Result of String
just curious about it . 对此感到好奇。 i wonder why :
我想知道为什么 :
string str = @"//
// Use a new char[] array of two characters (\r and \n) to break
// lines from into separate strings. \n Use RemoveEmptyEntries
// to make sure no empty strings get put in the string array.
//";
result text to richTextBox was: 结果文本到richTextBox是:
//
// Use a new char[] array of two characters (\r and \n) to break
// lines from into separate strings. \n Use RemoveEmptyEntries
// to make sure no empty strings get put in the string array.
//
but 但
string str = @"//
// Use a new char[] array of two characters (\r and \n) to break
// lines from into separate strings."+" \n" + @" Use RemoveEmptyEntries
// to make sure no empty strings get put in the string array.
//";
result text to richTextBox was: 结果文本到richTextBox是:
//
// Use a new char[] array of two characters (\r and \n) to break
// lines from into separate strings.
Use RemoveEmptyEntries
// to make sure no empty strings get put in the string array.
//
There is no literal @ before your central string " \\n" The equivalent would be 在中央字符串“ \\ n”之前没有文字@,等效于
string str = @"//
// Use a new char[] array of two characters (\r and \n) to break
// lines from into separate strings."+ @" \n" + @" Use RemoveEmptyEntries
// to make sure no empty strings get put in the string array.
//";
\\ is an escape character in normal strings, but string literals use the content exactly as is, except in the case of " which is escaped as "" \\是普通字符串中的转义字符,但是字符串文字完全按原样使用内容,除非“”被转义为“”
Because there is no @ before the "\\n" in you second example. 因为第二个示例中的“ \\ n”之前没有@。 Any escape sequence after @ (verbatim string literal) will be ignored.
@(verbatim字符串文字)之后的任何转义序列都将被忽略。 In your first example it was ignored but not in the second.
在第一个示例中,它被忽略,但在第二个示例中,它没有被忽略。
Have a look at this: http://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx 看看这个: http : //msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.