Im loading and splitting couple csv files into two lists in c#. Now I also need to extract the header from the first line with the ; as delmiter
. I'm trying to use the .Skip(1) command but that only skips (obviously) but I need to extract the header and after my work with the rest of the data is done add it again as the first line.
Here is what I have tried so far:
string[] fileNames = Directory.GetFiles(@"read\", "*.csv");
for (int i = 0; i < fileNames.Length; i++)
{
string file = @"read\" + Path.GetFileName(fileNames[i]);
var lines = File.ReadLines(file).Skip(1);
(List<string> dataA, List<string> dataB) = SplitAllTodataAAnddataB(lines);
var rowLog = 0;
foreach (var line in dataA)
{
// Variablen für lines
string[] entries = line.Split(';');
rowLog++;
Helper.checkdataAString(entries[0].ToLower(), "abc", rowLog);
Helper.checkdataAString(entries[1].ToLower(), "firstname", rowLog);
Helper.checkdataAString(entries[2].ToLower(), "lastname", rowLog);
Helper.checkdataAString(entries[4].ToLower(), "gender", rowLog);
Helper.checkdataAString(entries[5].ToLower(), "id", rowLog);
Helper.checkdataAString(entries[3], "date", rowLog);
Helper.drawTextProgressBar("loaded rown", rowLog, dataA.Count());
}
Console.WriteLine("\nencryypting data");
var output = new List<string>();
foreach (var line in dataA)
{
try
{
string[] entries = line.Split(';');
string abc = entries[0].ToLower();
string firstName = koeln.GetPhonetics(entries[1]).ToLower();
string lastName = koeln.GetPhonetics(entries[2]).ToLower();
string date = entries[3];
//Hier werden die drei vorherigen Variablen konkatiniert.
string NVG = FirstName + "_" + LastName + "_" + BirthDate;
string gender = entries[4].ToLower();
string age = Helper.Left(Convert.ToString(20171027 - Convert.ToInt32(entries[3])), 2);
string zid = Guid.NewGuid().ToString();
string fid = entries[5].ToLower();
rowdataA++;
output.Add($"{abc}; {NVG}; {gender}; {age}; {zid}; {fid}");
Helper.drawTextProgressBar("encrypted rows.", rowdataA, dataA.Count());
}
catch { rowdataA++; }
}
File.WriteAllLines(fileTest, output);
}
I'm kinda new to developing so im just trying and any help would be appreciated.