简体   繁体   中英

How to have openCSV CSVReader without a DEFAULT_QUOTE_CHARACTER?

I am using CSVReader to read from a tab delimited text file which has a field called "user_comments". In this column we can find all kinds of free form text which users have entered.

Here is the code where I declare my parser...

import au.com.bytecode.opencsv.CSVReader;

CSVReader csv = new CSVReader(new FileReader(opt.f),'\t' as char, '~' as char, '\0' as char);

The third argument to the constructor there is the "DEFAULT_QUOTE_CHARACTER". The default value is...

 public static final char DEFAULT_QUOTE_CHARACTER = '\"';

I set it to '~' because that "user_comments" column has values with double quotes inside of it (which should not be treated as actual quotes but should just be read as data from the column).

Problem is that column also has "~" and "|".

So can I create an instance of CSVReader without a default quote character? If not can you suggest a character I can use which is very rare and likely not found in this "user_comments" column?

Inspect Unicode's BMP plane ( http://unicode.org/roadmaps/bmp/ ) back to front. You're bound to find one that is "unlikely to be used in your data". Then use \\u.... to code it in your pgm source.

Or better still, use a codepoint that doesn't even represent a Unicode char, eg \퟇.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM