1

I'm trying to implement a CSV parser. Suppose I have an input string "a, a'b, c, d'c, b", and output should be a list of strings: "a", "a'b, c, d'c", "b". So basically it means all chars between ''should be a part of one string. The problem I am facing is that when I scan the input string, I cannot check if the char is ', because if(c==''') is invalid, because 'is an invalid character constant. So how should I check if a char in the input string is '?

hack_on
  • 2,532
  • 4
  • 26
  • 30
Ona
  • 89
  • 6

2 Answers2

1

There is an open source library that already does this called opencsv. You can use it directly or get the code from here.

hack_on
  • 2,532
  • 4
  • 26
  • 30
0

You need to escape the special character ' with a \. Take a look at the java documentation for more information.

b should be equal to true after executing this:

Character charValue = '\'';
boolean b = (charValue == '\'');
Cacho Santa
  • 6,846
  • 6
  • 41
  • 73