簡體   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