1

Labview has a simple function to read a .CSV file an convert it to a 2D array. The problem is that my .CSV file has strings and some of the strings have commas in them. Labview, and most C++ code examples, only separate the fields at commas. Chemical names like 1,1,1-trichloroethane should be a single field but would be broken into pieces. I need code that can see that when there is a comma-quote like ,"1,1,1-trichloroethane" and handle it differently from comma-only fields. I found code from Killzone Kid that can read and separate the fields from a .CSV file, but I also need to be able to write strings like this back into .CSV files.

  • CSV is much more complicated than pretty much everyone expects. While it's nice to be in the majority, sometimes it sucks. You're going to have to either write a lot of code to handle these cases or find a library that does it for you. We can help you with the first option. The second is off topic here. – user4581301 Nov 25 '19 at 20:48
  • 1
    Consider converting the .csv to a .tsv (tab separated values) if fields contain commas – Klaycon Nov 25 '19 at 20:49
  • Possible duplicate of https://stackoverflow.com/questions/35639083/c-csv-line-with-commas-and-strings-within-double-quotes/35639947#35639947 – Scott Hutchinson Nov 25 '19 at 21:10

1 Answers1

0

You might want to try Ryan Porter's Robust CSV package. (Source on github.) Robust CSV incorporates some work of P. Brooks' CSV parser but includes a writer and handles EOL variants on read.

Robert Calhoun
  • 4,823
  • 1
  • 38
  • 34