473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Need help ignoring commas within a csv file

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
2 2220
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
Thank you sir!

Cheers,
zdrakec

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Mike N. | last post by:
Hello: I have a form that contains a multiple-select field that has 12 options in it. I would like the user to be able to select UP TO FOUR of those options. If they select more than four, I...
3
by: darren | last post by:
Hello, I am posting a html form to a php processing page, which produces a csv file from the form data. However if the user inputs a comma then it screws up my data. So i'd like to know how...
7
by: AES | last post by:
Encountered a URL containing a comma the other day -- the first time I've ever noticed that, so far as I can recall. It worked fine, however, and I gather commas are legal in URLs. Out of...
2
by: Trint Smith | last post by:
Ok, My program has been formating .txt files for input into sql server and ran into a problem...the .txt is an export from an accounting package and is only supposed to contain comas (,) between...
4
by: striker | last post by:
I have a comma delimited text file that has multiple instances of multiple commas. Each file will contain approximatley 300 lines. For example: one, two, three,,,,four,five,,,,six one, two,...
4
by: Jason | last post by:
Could anyone spare some time and try to help me out. I've got a .txt data file with a name, pin, balance seperated by commas. I am opening the file and using Split to split it between the ,'s I...
3
by: Mike P | last post by:
I am trying to write a csv file to a database table, but the problem is that several fields have commas within them, so the code is reading the commas as the end of fields. My code is below. How...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
4
by: E11esar | last post by:
Hi there. This could be a curious one. Has anybody come across a solution to remove stray commas that appear within strings in a CSV file please? In effect I have many address fields that are...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.