C# remove trailing commas from csv file
Posted on 2016-10-26
We get csv files that have been written by macros in Excel and have no control over the content. so some rows have trailing commas, some have leading commas and some have both.
My goal is to remove these but I am having an issue either reading or writing the file and then applying the trimend, trimstart, etc.
So I get the file as a byte but you cannot perform those functions on a byte. I get the file to a String array String mystring but you cannot perform that either once you File.ReadAllLines into the String array....StringBuilder has no "row" so it isn't like a DataTable where I can do a foreach (DataRow DR in DT.Rows.Count)
There HAS to be an easy way to do this right? I am using file I/O native to the .NET framework version 4.51
Any help would be greatly appreciated.