0

*Edit: Im trying to use this in regards to QT6 The issue comes with reading a CSV file that is seperated by commas, as well as having embedded commas in quotes. Example:

example.csv
this is a pole,"made by: you, me",quantity:1
this is a pole, made by: me,quantity:2

What I am trying to do is make it where at a click off a button, it opens example.csv and another csv file with prices or quantities and edit the example.csv. Ive tried split() bc I read you can use a string as parameter of split, and tried adding a * after the commas that are seperators, and pass ",*" as the parameter..however it still splits at embedded commas.

What would be the best approach to make this work?

  • 1
    I'd recommend using a CSV parsing library rather than writing your own parser – Alan Birtles Sep 28 '21 at 20:05
  • I agree wholeheartedly with @AlanBirtles. CSV might seem as such a simple file format, but then you suddenly have embedded strings, which can contain commas, and even nested quoted strings, and suddenly it's all very complicated. You should really find a library which handles it for you, which have been tested to work for files like the one you want to read. Since it's such a common format, you might look if there isn't a parse already in the Qt framework. – Some programmer dude Sep 28 '21 at 20:30

1 Answers1

0

Regex Solution where you can exclusively get values between quotes. Assuming your CSV has some structure. It should be easy to create some logic around the expected CSV format and this regex.

If you are working with QT and doing some front-end work. Might want to look into QFile if you are not already using it

This reminds me of lexer/parser for compilers. You can look around for resources surrounding those topics as well.

Frebreeze
  • 202
  • 3
  • 10