Skip to content

Instantly share code, notes, and snippets.

@hylander0
Last active October 5, 2015 16:35
Show Gist options
  • Save hylander0/d9510001fb977cba3e6d to your computer and use it in GitHub Desktop.
Save hylander0/d9510001fb977cba3e6d to your computer and use it in GitHub Desktop.
Parse & Convert CSV using Pure Linq
private static List<CustomClassOfColumns> ParseCsv(string csvData)
{
csvData = csvData.TrimEnd('\r', '\n'); //Remove last CRLF
var items = from line in csvData
.Split(new string[] { Environment.NewLine }, StringSplitOptions.None) //Split each row
.Skip(1) //Skip column names
let col = line.Split(',') //split each column
select new CustomClassOfColumns()
{
col1 = col[0],
col2 = col[1],
col3 = col[2]
};
return items.ToList();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment