Earlier quoted context omitted.
it can be irritating, but you can just as easy parse ", " to "|" or something, by simple string replacing, pre parsing..
Think it through. What if there is free text in the field? "How are you, Sally?"
So You Want to Write Your Own CSV code
71–80 of 127 posts
Re: So You Want to Write Your Own CSV code
#72"CSV is not a well defined file-format. The RFC4180 does not represent reality. It seems as every program handles CSV in subtly different ways. Please do not inflict another one onto this world. Use a solid library." I can't but disagree when I read stuff like this. Why shouldn't I release a library if I think it's good enough for the community? Even the powerful and versatile Ruby library for CSV parsing started as…
Re: So You Want to Write Your Own CSV code
#73The most retard structure I've seen in a CSV file relates to the "What if the character separating fields is not a comma?". We get "CSV" files from Klarna, an invoicing company, with the payments they've processed for us. Because we're Danish and they are Swedish, it's not really weird that they would use comma as the decimal separator. So to compensate for having used the comma, they for some reason picks ", " ( tha…
In General Swedish csv files are separated with ; I have an function that I usually use in projects that counts , and ; on each line to determine which one is most likly beeing used in the file. The most annoying thing I have found in csv files is the escape sign I would like it to be \" but very often I see """ as the escape for "
Re: So You Want to Write Your Own CSV code
#74CSV works for simple cases. It is trivial to parse, you shouldn't even need a library. It there are many "what ifs" like in the posted article. You probably need another format like JSON (preferably) or XML.
Re: So You Want to Write Your Own CSV code
#75This article makes it much more complicated than it needs to be. It tries to be all things to all people. In practice you're going to have to sacrifice some functionality for the sake of usability and your own sanity. When I add a CSV import feature to a project I'm working on, I tell people "this works with MS Excel flavor of CSV." This covers most, if not all, real world cases because in my world the people who wan…
Re: So You Want to Write Your Own CSV code
#76I will solve your problem with only UNIX utilities. And I'm sure others will solve it other ways.
Usually I only need sed and tr. Sometimes lex or AWK.
Arguing about something without ever pointing to an example accomplishes nothing; it's just whining.
Post an example.
Thank you.
Re: So You Want to Write Your Own CSV code
#77Why are people using CSV when better (and less fuzzily defined) solutions exist, such as JSON?
Re: So You Want to Write Your Own CSV code
#78Re: So You Want to Write Your Own CSV code
#79CSV are a headache. Like the article says, RFC4180 doesn't necessarily represent the real world. However sometimes you just have to reject things that aren't spec. Not too long ago I was struggling with one of these CSV issues and received some good advice from Hans Passant [1] on a Stack Overflow question pertaining to my problem (emphasis mine): "It is pretty important that you don't try to fix it. That will make y…
Trying to compensate for bad CSV format will more likely cause headaches and confusion rather than clarity. It can also discourage the need for CSV writers to be rigorous about their output formatting.
Re: So You Want to Write Your Own CSV code
#80CSV works for simple cases. It is trivial to parse, you shouldn't even need a library. It there are many "what ifs" like in the posted article. You probably need another format like JSON (preferably) or XML.
However, that doesn't excuse sloppy CSV writers.