2015-09-23 43 views
0

已嘗試"\r\n"VS2003中的environment.newline以獲取換行符。我們使用"\r\n"或environment.newline在stringbuilder中編寫文本並將其保存在IO文件中。在IE11中打開文件時NewLine中斷不起作用,而在記事本中打開時文件起作用。如果它在IE8的舊版本中打開,這也適用。「 r n」或VS2003中的environment.newline不適用於IE11或Chrome

代碼的部分是:

StringBuilder cdataDescription = new StringBuilder(); 

cdataDescription.Append("* This is an install activity which passed through SYR.").Append(newline); 
       cdataDescription.Append("\r\n"); 
       //For CSI 
       cdataDescription.Append(" Please dispatch to the IBG * "); 
       cdataDescription.Append("\r\n"); 
       cdataDescription.AppendLine(); 
       cdataDescription.Append("test"); 
       cdataDescription.Append("\r\n"); 
       cdataDescription.Append("General Information"); 
       cdataDescription.Append("\r\n"); 
       cdataDescription.Append("---------------------------------------"); 
       cdataDescription.Append("\r\n"); 

string result = string.empty; 
result = cdataDescription.ToString(); 

return result; 
+3

那麼你在瀏覽器中打開一個純文本文件還是HTML?這裏沒有足夠的上下文... –

+1

使用
作爲新行,如果將其保存爲.html文件 – shreesha

+0

爲什麼不使用AppendLine而不是Append?期待記事本和任何版本的IE以相同的方式顯示文件是不合理的。一個用於編輯文本文件,另一個用於查看html文件。 – juharr

回答

-2

理想的新行字符是「\ n」只要寫一個文本文件conserned。 您可能需要檢查用於寫入文件的字符集。 Windows記事本只支持ASCII,你可以在Norepad ++中打開你的文件,因爲它支持不同的字符集。

另請注意UNIX和Windows風格。

+0

@UpasanaSingh,看看這個鏈接[類似問題](http://stackoverflow.com/questions/2986297/line-break-in-xml)。我想這裏的鏈接是一個類似的問題。對於您的問題,您需要使用
。 –

相關問題