Anand B
Anand B

Reputation: 3085

Ignore comma values while reading from csv files

I have a csv file which has 5 columns seperated by ",".

Problem occurs while reading csv when the columns have "," in data.

I tried using Opencsv, but it gave the same issue.

Upvotes: 2

Views: 5584

Answers (5)

Anand B
Anand B

Reputation: 3085

I modified the code to use semicolon as delimiter in csv. Now I can read data with "," correctly.

Upvotes: 1

Noob
Noob

Reputation: 38

Its not possible to identify comma which is part of value and comma part of CSV. Use different delimiter. values has to be surrounded by quotes. or Before converting to CSV convert all commas to some character which doesnt occur in your values , which can be reverted back in later stage.

Upvotes: 0

tofcoder
tofcoder

Reputation: 2382

If the column contains a comma (,), it must be enclosed by double quotes ("). A double quote can be escaped by repeating it (""). So, a line which includes values with commas must be represented as this:

"hello, world", "This says: ""hello, world"""

This line contains two values:

  • hello, world
  • This says: "hello, world"

Upvotes: 2

Pranav Kumar
Pranav Kumar

Reputation: 151

You need to use some other symbol to separate the words in csv file. I don't think there is a way to catch comma in words itself.

Upvotes: 0

David Hedlund
David Hedlund

Reputation: 129792

There is no way to distinguish a comma that is a part of your value from a comma that is intended to delimit two values. If your values will contain commas, and you have no way of escaping them, you'll have to use another delimiter.

Upvotes: 1

Related Questions