File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ignore commas in quoted elements while parsing CSV file

 
Ed Dablin
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
For example:
, , , 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.
Help appreciated....
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You specify the configuration as constructor arguments when you create an instance of CSVParser or CSVReader respectively.
 
Ed Dablin
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jelle Klap wrote:You specify the configuration as constructor arguments when you create an instance of CSVParser or CSVReader respectively.

Sorry, I don't know what you mean
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.):


etc.

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.
 
Winston Gutkowski
Bartender
Pie
Posts: 9477
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).

Winston

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic