Need help ignoring commas within a csv file

Z

zdrakec

I need to be able to do a Regex.split on a csv file ignoring the comma
if it is inside a single quote. I have the regular expression working
in the RegexDesigner tool, but when I use it within vb.net it adds an
extra split on each of the commas as well.

Example:
Reg Ex = ,(?=([^']*'[^']*')*(?![^']*'))
String to split = " '1A', 9, 2884, 'Sally, is late', 'nothing'

Works fine in the designer but output in vb.net looks like
element(0) = '1A'
element(1) = ,
element(2) = 9
element(3) = ,

etc...

Any help will be greatly appreciated!!

Thanks,
zdrakec
 
S

shriop

Despite the common thinking, regex's do not work for csv's. Even if you
find a regex that is somewhat close to handling what you need, it will
be slower than even the simplest string manipulation. If you're doing
this for production code, I would strongly recommend that you use one
of the several production level csv parsers available on the net.

Bruce Dunwiddie
http://www.csvreader.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top