Click here to Skip to main content
15,668,691 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a .csv file with hundreds of rows needing a comma added to the end of each row and remove the double quote near the beginning of the row. Is this possible in C#?:

"Linda Thorne -15076",297,153,53.54,35.03,6.19,5.24:50,00:18:30,05:52:49,67,297,22.56,100
"Gabriella Correa -15047",100,47,41.3,39,00:51:06,00:22:07,00:03:37,02:10:53,53,100,53,100
"Clarissa Thomas -15120",137,106,45.88,50:54,00:39:18,00:21:47,03:26:56,28,137,20.44,100

What I have tried:

This is part of an SSIS package that uses a For Each Loop Container and loads 14 .csv files and I've tried some C# Script but nothing works and I'm new to C#.
Updated 11-May-21 11:58am

1 solution

Yes, it's pretty simple - just ignore that "it's csv" and treat it as a text file.
Read all the lines using File.ReadAllLines, then use string.Trim('"') on each line, before appending the comma and either rewriting the file or handling it as a stream.

But ... if you remove the double quotes and add a comma, it won't parse as "normal CSV" - the double quotes delimit the first column data so it can contain commas if necessary, and the lack of a comma at the end of the line indicates the end of the row.
Your changes will render it unreadable as CSV data!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900