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

string parsing question

P: n/a
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
Share this Question
Share on Google+
4 Replies


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

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

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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.