By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,524 Members | 1,593 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,524 IT Pros & Developers. It's quick & easy.

Need help ignoring commas within a csv file

P: n/a
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

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

zdrakec wrote:
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


Nov 21 '05 #2

P: n/a
Thank you sir!

Cheers,
zdrakec

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.