Unix File in Windows Stream Reader
-
Morning All - I have a unix file / and Stream output that uses ^M [CTRL-M CR (Carriage return) ] to end a line. I see the line break's in MS Wordpad, but not in Notepad or when trying String.Split(char [], ...) I do not know what char to define. Can anybody help, or point me in the right direction. thx, CJ
-
Morning All - I have a unix file / and Stream output that uses ^M [CTRL-M CR (Carriage return) ] to end a line. I see the line break's in MS Wordpad, but not in Notepad or when trying String.Split(char [], ...) I do not know what char to define. Can anybody help, or point me in the right direction. thx, CJ
Are you writing the file or reading it? By default,
TextWriter.NewLine
is the same asEnvironment.NewLine
. If you need to change this, you can set theNewLine
property to any string necessary on classes that extendTextWriter
(likeStreamWriter
). If you're reading files using classes extending theTextReader
, many take an optional parameter (via overloads) to the control to automatically detect the file encoding, which most often checks the line-endings as well (IIRC). Take a look at the overloaded constructor documentation for theStreamReader
class in the .NET Framework SDK for more information. If you're wondering why wordpad.exe displays ^M it's most likely because it hasn't been updated to handle different line endings while notepad.exe has. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] -
Morning All - I have a unix file / and Stream output that uses ^M [CTRL-M CR (Carriage return) ] to end a line. I see the line break's in MS Wordpad, but not in Notepad or when trying String.Split(char [], ...) I do not know what char to define. Can anybody help, or point me in the right direction. thx, CJ
string.Split('\n') works just fine for *nix files :) top secret
Download xacc-ide 0.0.3 now!
See some screenshots