473,386 Members | 1,738 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,386 software developers and data experts.

Extra commas in CSV file

132 100+
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 punctuated with commas and I am looking for a way to remove these while parsing the csv file.

Any ideas will be most appreciated please.

Thank you.

Mark :)
Dec 19 '08 #1
4 4766
nukefusion
221 Expert 100+
I had a very similar issue myself with an application I created. It needed to produce a CSV file that could be imported into another vendors piece of software, but some of the fields contained address data, which could potentially contain commas.

I simply used the String.Replace() method to remove the commas and replace them with spaces, or another neutral character. You may well be able to apply a similar approach to your problem.
Dec 19 '08 #2
E11esar
132 100+
No that won't work for me as is as I am splitting the line as a string, using the delimited fields to populate a string array, hence in some cases the individual parts of the address string are being split into array cells, which is not serving its puprose well for me.

Ultimately the individual fields need to populate a database table so I need to keep the address lines in one field and so on.

Thank you.

M :)
Dec 19 '08 #3
nukefusion
221 Expert 100+
Really, if it's within your control, the best thing to do would be to stop the stray commas getting into the CSV file in the first place, or if the address field must have commas then put the field data between quotation marks. Then you could process it in your application as a literal string.

If you haven't got control over creation of the CSV file and the address fields aren't encapsulated within quotation marks, then you're dealing with a poorly formed CSV file and the only option would be to fudge it using some sort of heuristic analysis.
Dec 19 '08 #4
Ramk
61
@nukefusion
Why don't you try to use JET OLEDB. In which, you can parse the csv file(or any text file etc) by using OLEDB. You can define a custom schema in a file called schema.ini file.
Plz go through the following link for more info on schema.ini file.
Schema.ini File (Text File Driver)
Dec 20 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

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...
22
by: ineedyourluvin1 | last post by:
Hello all! I've been looking for a way to strip characters from strings such as a comma. This would be great for using a comma as a delimiter. I show you what I have right now. ...
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...
27
by: Peter Ammon | last post by:
My code obfuscator gave me this: char buff; to which gcc retorted: "ISO C90 forbids variable-size array 'buff'" and checking the standard, it appears that commas are indeed forbidden...
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,...
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...
3
by: Donkeyoz | last post by:
Hi all, Trying to do something fairly basic but am getting caught up on it. I am trying to extract text from a .txt file into an array line by line and then dissect that line into various parts,...
2
gregerly
by: gregerly | last post by:
I'm having an issue parsing a CSV file in which some fields contain commas. My CSV looks something like this: 123,asdflkj23klj,"Sept. 22, 2008",some field,one more field,"Aug 1,1983" To parse...
2
by: E11esar | last post by:
Hello there. I am reading in a CSV file and have found that where a field is null (empty) I need to replace this with a value, such as 0. In an ideal world the following command would work: ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.