Text Qualifiers

29 views
Skip to first unread message

SW

unread,
May 8, 2008, 5:44:13 AM5/8/08
to CSVChat
Hello

I am trying to output some data using the standard double quotes text
qualifier, where required (the default settings), but using the pipe
delimiter. I am however confused as to how the CSV writer determines
what to qualify.

I have data such as :

NULL, 1, Text, NULL, NULL, 3


and this is output as :

""|1|Text|||3


Im confused why the first NULL is always qualified, yet any further
nulls are not ?

The only way I can seem to stop the first field from being qualified,
if it is NULL, is to set UseTextQualifier to false. This seems to be
very inconsistent.

Regards
Stephen

shriop

unread,
May 10, 2008, 11:51:25 AM5/10/08
to CSVChat
Sorry for the late response. Yes, if you want to force the first
column to not have text qualifiers when the first column is empty,
then you'd have to turn off the text qualifier setting. This is
somewhat of a hidden "feature" in the component put there on purpose.
A lot of csv implementations will ignore blank lines, including
CsvReader depending on the setting. If there's a record with only one
column on it, and that column is empty, it's hard to differentiate a
blank line from a single empty cell, so in that case CsvWriter will
quote the first cell. And since it doesn't know at that time whether
there will be more than just the one cell on the line, this happens on
records with more than one cell on a line. The main rule in csv is
that text qualifiers, or the lack of, should never mean anything other
than specifying the escape sequence, so whether the first cell does or
doesn't have text qualifiers shouldn't matter. I have seen reasonably
high profile implementations like sql server however that export nulls
as non qualified and empty strings as qualified, but this is in no way
recommended for your own implementation. Sorry for the confusion, but
as you can see, it's a reasonably hard to explain feature.

Bruce Dunwiddie

On May 8, 4:44 am, SW <stephenwinstan...@asprey-solutions.co.uk>
wrote:

SW

unread,
May 12, 2008, 11:24:28 AM5/12/08
to CSVChat
Thank you, I understand why this occurs now, as the above does make
sense.

Unfortunately, as is often the case, I have to adhere to an existing
specification which disallows this, and all conversions have more than
one cell per line. I have for now specified the UseTextQualifier to
false, and this has resolved my immediate short term problems. I'm
told that you sell this product, with code included, and suspect that
is the option we will take, so we can tweak things to our requirements
for the longer term.

Regards
Stephen
> > Stephen- Hide quoted text -
>
> - Show quoted text -

shriop

unread,
May 12, 2008, 11:48:41 AM5/12/08
to CSVChat
That is definitely an option. And the code that controls that
particular piece is reasonably straightforward so it would be a fairly
simple change. You would just want to have a plan for how to merge
your changes into my current codebase when I send out an update. Let
me know if you decide to go this route as I only charge the difference
between what you originally paid and what the going rate is for the
source code version.

Bruce Dunwiddie

On May 12, 10:24 am, SW <stephenwinstan...@asprey-solutions.co.uk>
wrote:
> > - Show quoted text -- Hide quoted text -
Reply all
Reply to author
Forward
0 new messages