简体   繁体   中英

How do I use Super CSV on a delimited file that does not use a quote character?

I'm using Super CSV to parse a pipe ("|") separated file. The file does not use "text qualifiers", or what Super CSV calls a quote character. The problem is that Super CSV requires a quote character. I don't see a way to skip this, or provide a null character. Currently I'm passing some wacky unicode character that hopefully never appears in the input file.

Is there a way to have Super CSV parse a file without using a quote character?

I'm guessing that you don't have control of how the file to parse is written, and that it will never contain embedded pipe characters in the data?

The solutions I can see are:

  • Use a character that will never appear in your file (as you've suggested). This is a little dodgy, but will work.

  • Supply your own Tokenizer when you construct your Reader (you can copy the Super CSV implementation and just remove the quoting functionality).

  • Send us a feature request and we'll consider adding it. It may be simply a case of adding another preference which disables quoting when parsing.

I'll have a think about this, and see if I can think of the best way to achieve this.

Use the delimiter character as the quote character. Eg:

CsvPreference cp = new CsvPreference('|'/*quote char*/,'|'/*delimiter char*/, "\n");

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