At first this seemed obvious, but now I'm not so sure.
If a CSV file has the following line:
a,
I would interpret that as two fields with the values "a" and "". But then looking at an empty line, I could just as easily argue that it signifies one field with the value "".
I accept that an empty line at the end of the file should be interpreted as the end of the file (no field). But does anyone have any information on what an empty line within the file should mean?
Looking at how Excel handles empty lines when reading CSV files, I can see that Excel does not ignore them.
Unfortunately, there is no way to tell if the empty line was treated as an empty field or no fields at all because Excel always has the same number of columns.
I saw some proprietary uses of the CSV format where there was an option to how blank lines should be treated. In the end, this is the approach I took. My CSV reader class has four options for how to deal with empty lines:
If anyone's interested, I will be posting the new source code to replace the existing article at Reading and Writing CSV Files in C#.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With