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 :)
4 4805
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.
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 :)
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.
@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) Sign in to post your reply or Sign up for a free account.
Similar topics |
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 to strip my data of commas before submitting to the
php processor.
Or maybe not strip the commas but handle them better.
|
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.
#include<iostream>
#include<string>
int main(int argc, char *argv)
{
|
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 curiosity, did a quick scan of an ASCII file of the 542 URLs in
my personal bookmark file and discovered exactly 3 that contained commas
(two with a single comma, one with three commas) -- so I guess they're
pretty rarely used, even if legal.
Seems...
|
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
from being in a constant expression.
|
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, three,four,,,,,,,,,,eighteen, and so on.
There is one time when multiple commas are allowed. Just prior to the
letters ADMNSRC there should be one instance of 4 commas. (
,eight,,,,ADMNSRC,thirteen, ). The text ADMNSRC is NOT in the same
| |
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 do I get around
this?
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
StreamReader sr = new
StreamReader("\\\\devext02\\Xerox_Upload\\archive\\" + strFileName +
|
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, each part separated by a comma and placed into a different variable.
ie.
0001,dog,3,five,123
0002,cat,7,four,985
0003,pig,2,six_,435
0005,cow,4,nine,999
so when i dissect it, it comes out as:
|
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 my csv files I was reading it into an array with file(), and then looping the lines, exploding by comma, IE explode(',',$line), however this doesn't work as it will explode the commas in the date fields.
I guess my main question is how do I...
|
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:
stringName.Replace(",,", ",0,");
This does not work but I am wondering if there is a way to replace the double commas in the string with ,0, values?
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |