Link to home
Start Free TrialLog in
Avatar of praveen1981
praveen1981Flag for India

asked on

Split CSV File

Hi

I have the data as following in CSV File

vikram,vijay,hai,"nice,100" boy, "good,200"

now how can i split this data , can you please suggest.
Avatar of Pratima
Pratima
Flag of India image

StreamReader sr = new StreamReader("file.csv");
string inputLine = "";

String[] values = null;
while ((inputLine = input.ReadLine()) != null)
{
values = inputLine.Split(";");
}
input.Close();


 

 Loops over all the lines in the text file, and each time you have an string array with all the values for that line.
That would be very easy ...
in excel (2007/2010), from the ribbon, go to Data | From Text
User generated imageselect your file
 User generated imageon the first windows click next
User generated imageNOW HERE IS THE MAGIC TRICK: click on comma
 User generated imageand that's it ... next next next ...

Hope this clarifies what you want.
Avatar of praveen1981

ASKER

Hi

I want to do this in c#.net code

can u please suggest.
have you tried this , this is C#.net code

StreamReader sr = new StreamReader("file.csv");
string inputLine = "";

String[] values = null;
while ((inputLine = input.ReadLine()) != null)
{
values = inputLine.Split(";");
}
input.Close();
Hi

I have tried the above which is not working.
ASKER CERTIFIED SOLUTION
Avatar of Cimperiali
Cimperiali
Flag of Italy 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
This is an improperly formed comma separated file.
Excellent, it solved the problem,
Many Thanks.