0

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

3
Contributors
2
Replies
6
Views
7 Years
Discussion Span
Last Post by Dmennite
1

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

Edited by DanielGreen: n/a

Votes + Comments
Good to see another solver on the board :)
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.