Setting Line Endings

I’m hoping the kind folks here can help me out with the following question.

I am using StreamWriter in a Javascript script to write a text file from Unity.

The file it writes is perfectly readable and correctly formatted when I open it in OS X but in Windows the file appears to have no line endings and everything is mashed together. I’m assuming that the StreamWriter is using non-Windows line endings (\r\n).

So, I’ve looked through the .net documentation on this and there appears to be a way to set the kind of line endings used. However, I don’t know how to translate this to Javascript.

Can anyone help?

Here is the link to the .net documentation for this and below is the C# code they recommend: TextWriter.NewLine Property (System.IO) | Microsoft Learn

public virtual string NewLine { get; set; }

Thanks very much!
– Anthony

Something like

var sw = new StringWriter();
sw.NewLine = "\r\n";

I think, though I haven’t tried it.

–Eric

Hey Eric, that worked beautifully! Now the text files I output from Unity in OS X break their lines correctly when viewed in Notepad in Windows.

Many thanks. And I apologise for the long delay in response. It’s been very busy at work recently.

– Anthony