Hello,
Im looking to split eac row of my CSV file into an array, by separating it out by the commas, but taking care not to include the commas inside of quotations; " asd , dfg ".
How would i go about this?
Thanks for any help!
PS

Recommended Answers

All 2 Replies

hi!

take a look on :
http://knab.ws/blog/index.php?/archives/3-CSV-file-parser-and-writer-in-C-Part-1.html
http://knab.ws/blog/index.php?/archives/10-CSV-file-parser-and-writer-in-C-Part-2.html
http://www.codeproject.com/KB/database/CsvReader.aspx


or you can try this (with a regular expression):

private String[] LineToArray(String line)
{
  String pattern = ",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))";
  Regex r = new Regex(pattern);
  return r.Split(line);
}

Daniel

commented: Good to see another solver on the board :) +1

Not sure if it will work with what you are trying to accomplish

I know while loading file to a database I set
fields terminated by ','
enclosed by' " '

I am not sure how this could be applied to loading the csv to an array though

sorry

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.