0

Im trying to read a csv file and extract certain columns from the file and write them to a new file. Its all fine apart from when there is a comma in one of fields and its throwing everything thing out. e.g sample CSV

1 Mr John Smith 123 fake street, Fake Road, (commas causing issue)

My current code is

var lines = File.ReadLines(File1)
                 .Select(line => {
                     var col = line.Split(',');
                     return string.Join(",", col[0], col[1], col[2], col[3], col[4], col[5], col[6], col[7], col[8],
                          col[10]
                          , col[11], col[12], col[13], col[14], col[15], col[17], col[24], col[25], col[26]
                          , col[28], col[29], col[30], col[31], col[32], col[34], col[35], col[36], col[37]
                          , col[38], col[39], col[40], col[41], col[42], col[43], col[57], col[58], col[59]
                          , col[60], col[62], col[63]);
                 }).ToList();
            File.WriteAllLines(File1, lines);

Any quick ideas to fix the comma issue would be welcome.

CM99
  • 303
  • 2
  • 6
  • 19

0 Answers0