Link to home
Start Free TrialLog in
Avatar of lancerxe
lancerxe

asked on

replace commas in the double quotes so that I am able to use String.Split

I have a csv file that I'm trying to read.
It was working fine until they started adding the 2nd column
As you can imagine because of that , in the 2nd column the split
shifts eveyrthng.
Here's s a sample:
Account    Customer name      Amount  TC    Post Date Transaction Description
0000001    Rachel M, Friends  0.68        xx    Aug-10        DISCOVER NETWORK STARS
0000002    Donald M. Bner JR -28.8      xy   Aug-10     D CLARKE  - CHK ORDERS
I need to remove the , from Rachel M, Friends  before I do the split.

thanks
Avatar of the_b1ackfox
the_b1ackfox
Flag of United States of America image

1) read through the file once remove the commas, write the results to a temporary file, then process the newly created file, and run your split or 2) you could run a replace to remove all commas, then run your split()

Fox
SOLUTION
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shadow77
shadow77

If you want the commas removed, you can add a line such as
    s = Regex.Replace(s, ",", "");
to remove all commas from string s.
To be more precise, if you want the commas removed from within columns, replace line 23 with:
    currentField = Regex.Replace(currentField_loopVariable, ",", "");

@shadow77

My example is in C#  ;)
@kaufmed

Sorry if I was unclear.  I didn't mean to suggest any problem with your example.  I found a longer one with more detail on an MS site.  The MS example was in VB, so I translated it and added some comments.

Your pointing out the TextFieldParser class is the key contribution here.  That class is perfect for problems such as this.

;)
I misread your post, sorry  :)
Avatar of lancerxe

ASKER

I asked the client to send an excel spreadsheet instead.
thanks

lancerx