CsvReader icon indicating copy to clipboard operation
CsvReader copied to clipboard

Null versus Empty String fields

Open agilmore30 opened this issue 6 years ago • 2 comments

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

agilmore30 avatar Feb 11 '19 01:02 agilmore30

I'm using 4.0.0

agilmore30 avatar Feb 11 '19 01:02 agilmore30

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

fretje avatar Feb 26 '19 18:02 fretje