I'm trying to write a text file with Unix-style newlines with my C# program.
For some reason the following code doesn't work:
TextWriter fileTW = ...
fileTW.NewLine = "
";
fileTW.WriteLine("Hello World!");
Neither does this:
TextWriter fileTW = ...
fileTW.Write("Hello World! +
");
In both cases the '
' is being replaced with '
', which I don't want! I've been verifying this with a hex editor, which shows each line ending in 0x0D0A.
Any ideas?
Thanks!
EDIT:
Sorry everyone, false alarm!
Allow me to explain...
My TextWriter was writing to a MemoryStream, which was then being added to a tar archive using SharpZLib. It turns out that by extracting the text file using WinZIP, it was replacing every instance of
with
. If I copy the same tar archive to my Ubuntu machine and extract there, only the
is there. Weird!
Sorry if I wasted anyone's time! Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…