|
36 | 36 | * specification of a {@link CSVFormat}. |
37 | 37 | * |
38 | 38 | * <p> |
39 | | - * Parsing of a csv-string having tabs as separators, '"' as an optional value encapsulator, and comments starting with |
40 | | - * '#': |
| 39 | + * To parse a CSV input with tabs as separators, '"' (double-quote) as an optional value encapsulator, |
| 40 | + * and comments starting with '#', you write: |
41 | 41 | * </p> |
42 | 42 | * |
43 | 43 | * <pre> |
44 | | - * CSVFormat format = new CSVFormat('\t', '"', '#'); |
45 | 44 | * Reader in = new StringReader("a\tb\nc\td"); |
46 | | - * List<CSVRecord> records = new CSVParser(in, format).getRecords(); |
| 45 | + * Iterable<CSVRecord> parser = CSVFormat.newBuilder() |
| 46 | + * .withCommentStart('#') |
| 47 | + * .withDelimiter('\t') |
| 48 | + * .withQuoteChar('"').parse(in); |
| 49 | + * for (CSVRecord csvRecord : parse) { |
| 50 | + * ... |
| 51 | + * } |
47 | 52 | * </pre> |
48 | 53 | * |
49 | 54 | * <p> |
50 | | - * Parsing of a csv-string in Excel CSV format, using a for-each loop: |
| 55 | + * To parse CSV input in a given format like Excel, you write: |
51 | 56 | * </p> |
52 | 57 | * |
53 | 58 | * <pre> |
54 | 59 | * Reader in = new StringReader("a;b\nc;d"); |
55 | | - * CSVParser parser = new CSVParser(in, CSVFormat.EXCEL); |
| 60 | + * Iterable<CSVRecord> parser = CSVFormat.EXCEL.parse(in); |
56 | 61 | * for (CSVRecord record : parser) { |
57 | 62 | * ... |
58 | 63 | * } |
59 | 64 | * </pre> |
60 | | - * |
| 65 | + * <p> |
| 66 | + * You may also get a List of records: |
| 67 | + * </p> |
| 68 | + * <pre> |
| 69 | + * Reader in = new StringReader("a;b\nc;d"); |
| 70 | + * CSVParser parser = new CSVParser(in, CSVFormat.EXCEL); |
| 71 | + * List<CSVRecord> list = parser.getRecords(); |
| 72 | + * </pre> |
61 | 73 | * <p> |
62 | 74 | * Internal parser state is completely covered by the format and the reader-state. |
63 | 75 | * </p> |
|
0 commit comments