I have a csv file that looks like this
Names.csv
"Name1", "Name2", "Name8", "Name4", "Name5", "Name6" , "Name7", "Name3" , "Name9"
In C# I would like to user Linq to do the following
open file read the names, parse them out and strip off the double quotes then order them by name and write them to Name.out file.
output
1- Name1
2- Name2
3- Name3
4- Name4
5- Name5
6- Name67- Name7
8- Name8
9- Name9
VulpesRank #55 · 29.2K reputationPosted Apr 12, 2014, 3:30 AM EDT
File.WriteAllLines("Name.out", File.ReadAllText("Names.csv").Replace("\"", "")
.Split(new[]{", "}, StringSplitOptions.None).OrderBy(n => n)
.Select((n,i) => (i+1) + " - " + n).ToArray());
Lawrence Pond149 reputationPosted Apr 12, 2014, 8:56 PM EDT
VulpesRank #55 · 29.2K reputationPosted Apr 13, 2014, 12:31 AM EDT