You need to use a parsing method that is more sophisticated than a simple split on a character.
At a minimum, it should have two modes, Splitting and Skipping. Then the logic would look like this
- Start in Splitting mode.
- Read a character.
- If in skipping mode, and the character is a quote, then shift to splitting mode.
- If in splitting mode, and the character is a comma, then split.
- If in splitting mode, and the character is a quote, then shift to skipping mode.
- Continue at 2 until all characters are read.
Learning how to parse is a very useful tool, even though there are plenty of pre-built parsers out there. There are always problems that require "just" enough parsing to require you to roll a new tool.
With that in mind, I'd first reach for a CSV file parsing tool.
Then, in some cases, regex parsing might be a good choice.
Finally, rolling your own parser might be advisable, but if you do, please read up on discrete finite automata.
If you learn DFA, those that don't understand the math behind it will marvel that your parsers work, and a well built DFA is often very fast.