c# – convert unix file – Education Career Blog

I received some large text files with a Unix line break (I think). I usually open small files in my text editor and save them as PC text file but these files are too big for this approach. So I thought I write a little C# program.

I usually use something like this:

using (TextReader tr = File.OpenText(@"D:\bla.txt"))
            {
                string line;
                while ((line = tr.ReadLine()) != null)
                {
                    string items = line.Split('|');

but the Unix line break causes problem. I would appreciate any suggestions. Thanks!

Christian

,

Unix line breaks shouldn’t cause any problems for TextReader.ReadLine – it’s specifically designed to cope with any line break. From the docs:

A line is defined as a sequence of characters followed by a carriage return (0x000d), a line feed (0x000a), a carriage return followed by a line feed, Environment.NewLine, or the end of stream marker. The string that is returned does not contain the terminating carriage return and/or line feed. The returned value is null if the end of the input stream has been reached.

This flexible definition includes the normal Unix line break of “\n”.

I suspect your problem lies elsewhere. You haven’t actually said what problems you believe are caused by the Unix line breaks. What’s going wrong at the moment?

,

Just use ToFroWin.

Leave a Comment