I'm working with a large CSV data file.
Some of the data elements contain commas. In these cases the element is enclosed by quotation marks.
, , , blah , blah blah , Murder Incorporated Inc. , "Murder Incorporated, Inc." , blah blah blah , , ,
I want my parser to ignore the comma between the quotes.
I've learned that OpenCSV supports "ignoring commas in quoted elements".
OpenCSV But I can't find the method to do so.
If you look at the API documentation I linked to for either of the two classes, you'll find several overloaded constructors for each class.
Those overloaded constructors allow you to configure their behavior, for instance (also in the OpenCSV FAQ.):
Unless you instantiate a CSVParser with the overloaded constructor that accepts the ignoreQuotations boolean flag, the default behaviour of the CSVParser should be to ignore seperator characters within quoted sections, unless quotes are escaped with the default/specified escapeChar, which means your sample data should be parsed the way you want it to. That is unless you set the strictQuotes flag, which will cause any data between seperators that is not quoted to be returned as an empty String value.
Ed Dablin wrote:Sorry, I don't know what you mean...
I hate to sound brutal, but if you still don't after reading the documentation and the links that Jelle provided, then maybe you're not quite ready for this problem.
Programming is not simple, and it's no failure to admit that you can't do something. In fact, it's a sign of wisdom - and not just in programming.
Just remember - all it means is you can't do it YET (←click).
Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here