473,545 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1378
On Wed, 11 Oct 2006 07:00:02 -0700, igotyourdotnet
<ig************ @nospam.nospamw rote:
>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.Len gth-1; ++i) fields[3] += "," +
fieldParse[i];
fields[4] = fieldParse[fieldParse.Leng th -1];

-- bruce (sqlwork.com)
"igotyourdotnet " <ig************ @nospam.nospamw rote in message
news:5E******** *************** ***********@mic rosoft.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
3896
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 varible. I want to grab .pls files from shoutcast and break them into varibles. ----------------Begin winamp.pls file-------------------
15
3603
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" -zug into: ,
26
808
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 .txt-file in which the data is structured in that way: Project-Nr. ID name lastname 33 9 Lars Lundel 33 12 Emil Korla
10
2615
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 integers. What is the best standard(!) C++ way to accomplish this? -- Christopher Benson-Manica | I *should* know what I'm talking about - if I...
8
8393
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 "CC123-aaa.456-bbb-789" The question I have is, given the newstring and the
29
4232
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
2066
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
1403
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 search/replace on the "&" char with the "amp&;" prior to parsing??
1
4357
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 Stack code and parsing code my professor i does not like me using buffer reader on my code and my professor did even give me an example code for parsing...
0
7502
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, 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...
0
7434
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...
0
7692
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, 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. ...
0
7791
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6026
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1045
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
744
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.