Question by
tperry1x · Nov 11, 2015 at 11:17 PM ·
returnlinesstring formattingnewline
newline character replacement in a string?
I have a string in tstring. It's in the form of A,B,C,D,E,F
I want to replace the commas with returns. So I use
tstring = tstring.Replace(",",System.Environment.NewLine);
I write this string to file with:
var fileName = "save.txt";
var fw = new StreamWriter(Application.dataPath + "/data/" + fileName);
fw.Write (tstring);
fw.Close();
When I open save.txt it reads ABCDEF
I've tried replacing with "\n" instead, but with the same result. Any ideas and help appreciated!
Comment
Best Answer
Answer by tperry1x · Nov 11, 2015 at 11:29 PM
Ah, love it when I'm able to answer my own question. My string tstring was an array. I just needed to join it together with
var finalsavedata = Array(mysavedata).Join(System.Environment.NewLine);
When I write the file now, I get what I expected:
A
B
C
D
E
F