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

string parsing question

I have a question.
I'm reading a CSV file that is uploading to my SQL db, I'm parsing out the
file line by line. I'm getting the values and putting them into an arrayList
seperate by commas. The problem I'm having is that one of the data values has
commas in it so its blowing up on the other fields. How can I remove the
commas from my string if they exist?

example:
Getting this
BMW, Used, 325C, $19,252.00, Smith

due to the comma in 19,252.00 its thinking its a new value at 252
So if this is the case how can I remove the commas in arraylist[4] data item?
Now that field will not have a comma all the time or will it be in the same
place it can have 1,252,252.00 or 1252.00 or 5,252.00 . is this possible to
do?


Oct 11 '06 #1
4 1368
On Wed, 11 Oct 2006 07:00:02 -0700, igotyourdotnet
<ig************@nospam.nospamwrote:
>I have a question.
I'm reading a CSV file that is uploading to my SQL db, I'm parsing out the
file line by line. I'm getting the values and putting them into an arrayList
seperate by commas. The problem I'm having is that one of the data values has
commas in it so its blowing up on the other fields. How can I remove the
commas from my string if they exist?

example:
Getting this
BMW, Used, 325C, $19,252.00, Smith

due to the comma in 19,252.00 its thinking its a new value at 252
So if this is the case how can I remove the commas in arraylist[4] data item?
Now that field will not have a comma all the time or will it be in the same
place it can have 1,252,252.00 or 1252.00 or 5,252.00 . is this possible to
do?
String.Replace(.. shoud work. Am I missing something here?
Peter Kellner
http://peterkellner.net
Oct 11 '06 #2
You could use String.Replace(",","")

igotyourdotnet wrote:
I have a question.
I'm reading a CSV file that is uploading to my SQL db, I'm parsing out the
file line by line. I'm getting the values and putting them into an arrayList
seperate by commas. The problem I'm having is that one of the data values has
commas in it so its blowing up on the other fields. How can I remove the
commas from my string if they exist?

example:
Getting this
BMW, Used, 325C, $19,252.00, Smith

due to the comma in 19,252.00 its thinking its a new value at 252
So if this is the case how can I remove the commas in arraylist[4] data item?
Now that field will not have a comma all the time or will it be in the same
place it can have 1,252,252.00 or 1252.00 or 5,252.00 . is this possible to
do?
Oct 11 '06 #3
assuming only the dollar field has extra commas then
string[] fieldParse = line.Split(',');
for (int i=0; i < 4; ++i) fields[i] = fieldParse[i];
for (int i=4; i < fieldsParse.Length-1; ++i) fields[3] += "," +
fieldParse[i];
fields[4] = fieldParse[fieldParse.Length -1];

-- bruce (sqlwork.com)
"igotyourdotnet" <ig************@nospam.nospamwrote in message
news:5E**********************************@microsof t.com...
>I have a question.
I'm reading a CSV file that is uploading to my SQL db, I'm parsing out the
file line by line. I'm getting the values and putting them into an
arrayList
seperate by commas. The problem I'm having is that one of the data values
has
commas in it so its blowing up on the other fields. How can I remove the
commas from my string if they exist?

example:
Getting this
BMW, Used, 325C, $19,252.00, Smith

due to the comma in 19,252.00 its thinking its a new value at 252
So if this is the case how can I remove the commas in arraylist[4] data
item?
Now that field will not have a comma all the time or will it be in the
same
place it can have 1,252,252.00 or 1252.00 or 5,252.00 . is this possible
to
do?


Oct 11 '06 #4
Hi igotyourdotnet,

I think the problem here is that both the cell(column)'s separator and the
currency's separator use the comma. I'm wondering whether your CSV sheet's
table structure is fixed, in other words whether the column count is fixed
and the currency($.xxxx) will always occur at the fixed column index in the
columns of each row?

If this structuer is fixed , your string path can use the following logic
to pickup the corret columns from each string line:

1) use string.Split to get the string array separated by comma

2) read the prior columns before the currency column

3) read the last columns (from the end of the array) which is behind the
currency column

4) and for those array items left, they should be recombined to construct
the currency value.

Please feel free to post here if you have any other concerns or ideas.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 12 '06 #5

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

Similar topics

2
by: Michael Hogan | last post by:
I want to pars a playlist file for three different varibles, so I can save them as mp3 files. I am using: strTEMPURL = GetUrlSource(Text1.Text) to put the entire .pls file into a strTEMPURL...
15
by: Freddie | last post by:
Happy new year! Since I have run out of alcohol, I'll ask a question that I haven't really worked out an answer for yet. Is there an elegant way to turn something like: > moo cow "farmer john"...
26
by: Kai Jaensch | last post by:
Hello, i am an newbie and i have to to solve this problem as fast as i can. But at this time i donīt have a lot of success. Can anybody help me (and understand my english :-))? I have a...
10
by: Christopher Benson-Manica | last post by:
(if this is a FAQ, I apologize for not finding it) I have a C-style string that I'd like to cleanly separate into tokens (based on the '.' character) and then convert those tokens to unsigned...
8
by: Bob Davis | last post by:
In C# one can construct a string using the format method. for example string newstring = string.Format("CC%d-%s.%d-%s-% d",123,"aaaa",456,"bbb",789); The resulting newstring will be...
29
by: zoltan | last post by:
Hi, The scenario is like this : struct ns_rr { const u_char* rdata; }; The rdata field contains some fields such as :
3
by: dimasteg | last post by:
Hi all C. Nead some help with string "on the fly" parsing, how it can be realized ? Any ideas? I got some of my own, but it's interesting to get other points of view . Regards.
0
by: bruce | last post by:
Hi Fredrick Thanks for the reply. But since I don't have control of the initial text, is there something with python that will strip/replace this... or are you saying I should do a...
1
by: eyeore | last post by:
Hello everyone my String reverse code works but my professor wants me to use pop top push or Stack code and parsing code could you please teach me how to make this code work with pop top push or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: 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
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
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
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...

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.