I have a CSV file (which I did not create, and now I canβt change it and I canβt change it), containing the following lines:
"Surname, Firstname", yes, no, somestring, whatever, etc
As you can see here, the first is ,not a comma by which I want to split the line. Note that this comma is enclosed in quotation marks.
Because of this, simple string.split(',')will obviously not work, as it will provide me with an array of length 7 for the specified string instead of 6.
Is there any way around this? I was thinking about using a regex to separate a string, but I am not competent enough in regex to think of a pattern that will only be separated by commas that are not enclosed in quotation marks.
I can think of ugly, hacker ways to do this by reading every line of char on char, but this should be the last resort, as I am sure there is a better way to do this!
source
share