0

As far as I can tell, this method is returning a blank line every other line, but I can't figure out why:

public static List<string> plain(string path, int num)
        {
            List<string> result = new List<string>();
            StreamReader reader = File.OpenText(path);
            string line;
            int i = 0;
            while ((line = reader.ReadLine()) != null)
            {
                result.Add(line);
                i++;
                if (i == num) { break; }
            }
            return result;
        }

Does anyone have an idea? I'm sure it's something simple I'm overlooking :).

4
Contributors
6
Replies
7
Views
8 Years
Discussion Span
Last Post by lighthead
1

Your function is correctly returning a list of at most 'num' lines in the file. There were no blank lines. You might want to recheck other parts of the program.

1

Yeah .. it also works fine here.

P.S. Are you sure, that your file, which lays in path has text in it (maybe this is that simple, that you're overlooking :P)?

0

In that case you might want to use this:

line.Replace("\\r\\r\\n", "");

That should fix it :-)

0

Yeah I just wrote a Python script to fix the files. Python's pretty quick to write, this is the first time it has frustrated me :).

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.