Click here to Skip to main content
15,561,685 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a csv file and in the following format can any one please do send me solution as soon as possible

"sar","ca","employee, orgna"

"employee, orgna"
is being treated as a dual colum since , is delimiter can any one provide me solution so that i can remove extra , from this and i am sending code the way i am reading csv file
Posted

You are obviously reading the CSV incorrectly. When you encounter quotes, read all characters until the next quote, then start checking for commas again. You'll probably also want to account for the situation where a double quote appears in the value.
 
Share this answer
 
You need to manually join the strings at index 2 and index 3.

string employeeOrgna = string[2] + " " + string[3];

then write it back to a new csv file. Its a programatic error that is based on the fact that when you are using the Split function for the string, its delimiting of every single "," as you have found out. The way to fix it is to realise that the number of columns in the particular csv file should be fixed to a constant value. This way you can use a constant index and join the two together.

An alternative (if the number of columns is going to change) is to use RegularExpressions and look into the "Groups" function for RegEx's. This way you can use a clever mechanism to split at certain locations in each line of the csv.

Dave
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900