Mbali Ngobeni

Mbali Ngobeni

  • NA
  • 28
  • 2k

Change column header of CSV and date format

Aug 29 2020 9:00 AM

I need help changing the csv values. Bit under pressure now, I have only written script for the header portion. Even that is not working.

ACCOUNT

DATE

INVOICE

AMOUNT

 

11204

24.06.2019

90280482

166.38

 

11204

24.06.2019

90280481

2792.7

 

11204

24.06.2019

90280483

354.95

 

11204

24.06.2019

90280485

50.4

 
         
 
My code.
string[] myfile = File.ReadAllLines(csvFile);
string[] header = myfile[0].Split(',');
List<string> newLines = new List<string>();
for (int z=0; z<header.Count();z++)
{
if (header[z] == "AMOUNT")
{
var totheader = header[z].Replace("AMOUNT","TOTAL");
header[z] = totheader;
}
string newLine = string.Join(",", header);
newLines.Add(newLine);
}
File.WriteAllLines(myfile[0], newLines.ToArray());
 
 

I need to change

1. AMOUNT header to TOTAL

2. The date field need to change to 2019-06-24

I need help changing the csv values. Bit under pressure now, I have only written script for the header portion. Even that is not working.

 Results should be

 

ACCOUNT

DATE

INVOICE

TOTAL

 

11204

2019-06-24

90280482

166.38

 

11204

2019-06-24

90280481

2792.7

 

11204

2019-06-24

90280483

354.95

 

11204

2019-06-24

90280485

50.4

 
         

Thank you in advance.


Answers (6)