If field includes a comma or a new line, the whole field must be surrounded with double quotes. When the field is in quotes, any quote literals must be escaped by \" Backslash literals must be escaped by \\. Otherwise a backslash an the character following it will be treated as the following character, ie."\n" is equivelent to "n". Other escape sequences may be set using the setEscapes() method. Text that comes after quotes that have been closed but come before the next comma will be ignored.
Empty fields are returned as as String of length zero: "". The following line has three empty fields and three non-empty fields in it. There is an empty field on each end, and one in the middle. One token is returned as a space.
,second,, ,fifth,
Blank lines are always ignored. Other lines will be ignored if they start with a comment character as set by the setCommentStart() method.
An example of how CVSLexer might be used:
CSVParser shredder = new CSVParser(System.in); shredder.setCommentStart("#;!"); shredder.setEscapes("nrtf", "\n\r\t\f"); String t; while ((t = shredder.nextValue()) != null) { System.out.println("" + shredder.lastLineNumber() + " " + t); }
Some applications do not output CSV according to the generally accepted standards and this parse may not be able to handle it. One such application is the Microsoft Excel spreadsheet. A separate class must be use to read Excel CSV. @see com.Ostermiller.util.ExcelCSVParser
|
|
|
|
|
|
|
|