2016-07-20 5 views
0

エディタにテキストを保存しようとすると、結果1が、Androidデバイスの区切られた行にテキストを保存するときに表示されますこの結果2のような結果としているUnityで区切られた行をファイルに保存する方法#

result 1 is 
a 
b 
c 
d 

result 2 is 
abcd 

はここWriteLine

0123のドキュメントによると、私のコード

public void savetofile() 
{ 
    StreamWriter SW = new StreamWriter(" path to file "); 
    SW.WriteLine("a"); 
    SW.WriteLine("b"); 
    SW.WriteLine("c"); 
    SW.WriteLine("d"); 
} 

です

文字列またはストリームに行終端文字を続けて記述します。

各行は改行で最後に印刷する必要がありますが、例で示したようにこれは起こりません。誰かが間違っていることを教えてもらえますか?

+0

使用SW.WriteLine( "/ R/N")。 –

答えて

0

制御コード "\ n"を新しい行に使用できます。

public void savetofile() 
{ 
    StreamWriter SW = new StreamWriter(" path to file "); 
    SW.WriteLine("a"); 
    SW.WriteLine("/n"); 
    SW.WriteLine("b"); 
    SW.WriteLine("/n"); 
    SW.WriteLine("c"); 
    SW.WriteLine("/n"); 
    SW.WriteLine("d"); 
} 
+0

まだ動作していない結果は "a/nb/nc/nd/n" –

+0

SW.WriteLine( "/ r/n");が動作しない場合は、行終端文字列を設定してみてください。https://msdn.microsoft.com/en-us/library/system.io.textwriter.newline(v=vs.110).aspxまたはEnvironment.NewLineを使用してください – Shredsauce

0

文字列を宣言しようと思うかもしれません。

StreamWriter SW = new StreamWriter(" path to file "); 
string s = "a 
      b 
      c 
      d"; 
SW.WriteLine(s); 
関連する問題