The best solution is "don't" - CSV data isn't just "separated by comma" it can also contain quoted strings, which can legitimately contain commas.
Instead of "rolling your own" solution here, have a look at this:
A Fast CSV Reader[
^] - it does all the hard work for you!