# StringSplit on comma but ignore commas in quotes [closed]

I'm importing CSV files and some of the fields include quoted text with commas as part of the field, rather than as a field separator. What is the syntax (or alternative method entirely) to import and split the string by comma, while ignoring commas within quotes?

raw = ReadList[file, String];
StringSplit[raw[[#]], ","] &/@Range@Length@raw


This splits each line of the file on commas, but for lines like:

a,b,"c,c",d,e


I get:

a
b
"c
c"
d
e


whereas I would like:

a
b
"c,c"
d
e


(I have represented the elements of the example line as a column to emphasize unique fields)

• I think if your provide your CSV files,you will get more beauty solution
– yode
Jun 28 '16 at 18:38
• @yode - we can try to just experiment with the one line, StringSplit["a,b,\"c,c\",d,e", ","]  to try and get it to work Jun 28 '16 at 18:41
• Jun 28 '16 at 18:54

I found the problem is with my original data; there are some unexpected Line Feed characters in my data which were causing me to misinterpret the result of "Import" using type CSV. The comments by Yode and JasonB prompted me to look at the file with notepad++ so I could see the LF characters. Sorry for the confusion.

• If your Line Feed are within quotes, there is a solution here Jun 28 '16 at 19:01
• I'll try to get the linefeeds removed from the original source material as they are not supposed to be there, but these references given by Andre and Szabolcs are most helpful and very informative. Jun 28 '16 at 19:13