Skip to main content
3 of 4
added 86 characters in body
george2079
  • 39.1k
  • 1
  • 44
  • 111

Here is a start..

Export["test.txt", "a1,b1,c1,d1,\"e1\ne1\ne1\"\na2,b2,\"c2\nc2\nc2\",d2,e2"]

i = 0;
StringSplit[StringJoin[#], ","] & /@ 
  Split[Characters[Import["test.txt", "Text"]],
   (If[# == "\"", ++i]; ! (# == "\n" && EvenQ[i]) ) &]

Note this will break if there are commas within quoted strings.

Edit: a bit more elegant..and this takes care of the comma-within-quotes issue.

stringsplitnoquote[string_String, d_String /; StringLength[d] == 1] :=
  Module[{i = 1},
  StringSplit[
   string, _?((If[# == "\"", i *= -1]; i == 1 && # == d) &)]]

stringsplitnoquote[#, ","] & /@ 
     stringsplitnoquote[ Import["test.txt", "Text"] , "\n"]

Due credit.. borrowed from here : http://mathematica.stackexchange.com/a/103030/2079

george2079
  • 39.1k
  • 1
  • 44
  • 111