0

Is it possible to read a csv file where the values are separated by a string rather than a single character? Earlier the csv file had a comma separator, but now it is being created with a string separator "###". I don't have any control over the creation of the csv file.

I'm using the Opencsv library http://sourceforge.net/projects/opencsv/ and it does not seem to have support for string separator only characters.

Is there a way to solve the above? Are there any good and similar alternatives to the Opencsv library?

1 Answer 1

-3

The docs give you an example of how to do this. See http://opencsv.sourceforge.net/#custom-sepators.

Can I use my own separators and quote characters?
Yes. There are constructors that cater for supplying your own separator and quote characters. Say you're using a tab for your separator, you can do something like this:

  CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t');

And if you single quoted your escaped characters rather than double quote them, you can use the three arg constructor:

  CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t', '\'');
Sign up to request clarification or add additional context in comments.

3 Comments

I've read that and they mention only single characters, not strings of characters
@aldrin Apparently there is no open source Java library that can handle multi-character CSV separators, as per my recent relevant question (stackoverflow.com/questions/8653797/…). If, however, in the mean time you have found one, please contribute there.
@PNS no i didn't find an alternative. I tried to modify OpenCSV to process multi-char separators, but it wasn't trivial. So I eventually replaced the multichars with a single char as a preprocessing step and continued.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.