繁体   English   中英

字符串的奇怪结果

[英]Weird Result of String

对此感到好奇。 我想知道为什么 :

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. 
    //";

结果文本到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. 
    //

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. 
    //";

结果文本到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. 
    //

在中央字符串“ \\ 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. 
//";

\\是普通字符串中的转义字符,但是字符串文字完全按原样使用内容,除非“”被转义为“”

因为第二个示例中的“ \\ n”之前没有@。 @(verbatim字符串文字)之后的任何转义序列都将被忽略。 在第一个示例中,它被忽略,但在第二个示例中,它没有被忽略。

看看这个: http : //msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM