diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java index 7be97b33..966edd02 100644 --- a/src/main/java/org/apache/commons/csv/CSVParser.java +++ b/src/main/java/org/apache/commons/csv/CSVParser.java @@ -36,28 +36,40 @@ import java.util.NoSuchElementException; * specification of a {@link CSVFormat}. * *
- * Parsing of a csv-string having tabs as separators, '"' as an optional value encapsulator, and comments starting with - * '#': + * To parse a CSV input with tabs as separators, '"' (double-quote) as an optional value encapsulator, + * and comments starting with '#', you write: *
* *- * CSVFormat format = new CSVFormat('\t', '"', '#'); * Reader in = new StringReader("a\tb\nc\td"); - * List<CSVRecord> records = new CSVParser(in, format).getRecords(); + * Iterable<CSVRecord> parser = CSVFormat.newBuilder() + * .withCommentStart('#') + * .withDelimiter('\t') + * .withQuoteChar('"').parse(in); + * for (CSVRecord csvRecord : parse) { + * ... + * } ** *
- * Parsing of a csv-string in Excel CSV format, using a for-each loop: + * To parse CSV input in a given format like Excel, you write: *
* ** Reader in = new StringReader("a;b\nc;d"); - * CSVParser parser = new CSVParser(in, CSVFormat.EXCEL); + * Iterable<CSVRecord> parser = CSVFormat.EXCEL.parse(in); * for (CSVRecord record : parser) { * ... * } *- * + *
+ * You may also get a List of records: + *
+ *+ * Reader in = new StringReader("a;b\nc;d"); + * CSVParser parser = new CSVParser(in, CSVFormat.EXCEL); + * List<CSVRecord> list = parser.getRecords(); + **
* Internal parser state is completely covered by the format and the reader-state. *