CsvReader
CsvReader copied to clipboard
Null versus Empty String fields
Hi
First, thanks for an awesome piece of code. Very useful.
I am testing for null and empty string values. e.g.
Row 1 - "A",,"C" is returned by CSVReader as the string array [A","","C"] Row 2 - "A","","C" is also returned as [A","","C"]
There doesn't seem to be any distinction between a null string and an empty string.
I would like row 1 to return as ["A",null,"B"]
Empty string and null can have different meanings in some applications.
Question 1. Is there a way to affect that behavior now ? Question 2. If not, is it possible to add a constructor parameter or property, with some logic, to change the behavior.
Thanks - Adam
I'm using 4.0.0
The CsvReader class actually has some constructors where you can supply a "nullvalue" parameter. This is by default an empty string. So that means that by default all empty strings are handled as null values. If you supply your own string there, e.g. "_null_
" then only that string will be handled as a null value, and empty strings will be handled as empty strings.
See also https://github.com/phatcher/CsvReader/pull/2