Last active
October 5, 2015 16:35
-
-
Save hylander0/d9510001fb977cba3e6d to your computer and use it in GitHub Desktop.
Parse & Convert CSV using Pure Linq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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