Hello,

I'm trying to replace an old CSV library with commons-csv. I seem to be having 
trouble with the most basic idea of the parser recognizing content that is 
quoted.


I'm using Commons CSV 1.7 and Open CSV 4.6.


Here is a code snippet with OpenCSV and Commons CSV:


import com.opencsv.CSVReader;

import org.apache.commons.csv.CSVFormat;

import org.apache.commons.csv.CSVParser;

System.out.println("OpenCSV");
CSVReader reader = new CSVReader(new StringReader("1, 2, \"A, B\", 4"));
reader.iterator().forEachRemaining((sa) -> {
  Arrays.stream(sa).forEach((s) -> System.out.println(s.trim()));
});

System.out.println("Commons CSV");
CSVParser parser = CSVFormat.DEFAULT.withTrim().parse(new StringReader("1, 2, 
\"A, B\", 4"));
parser.iterator().next().iterator().forEachRemaining(System.out::println);

The output is:


OpenCSV

1

2

A, B

4

Commons CSV

1

2

"A

B"

4


My expectation is that OpenCSV and Commons CSV would yield the same results 
(which would also agree with the library I'm yanking out).


I've tried fiddling with settings and with different CSVFormat instances with 
no change in behavior.


Any help appreciated.


--

Daryl Stultz
Principal Software Developer
_____________________________________
OpenTempo, Inc
http://www.opentempo.com<http://www.opentempo.com/>
mailto:daryl.stu...@opentempo.com<mailto:daryl.stu...@opentempo.com>

Reply via email to