I have splitted files, from the main file.
The main file looks like this:
Y, ,09/30/16 10:48:40,c,1,.84054972,0,P,0,0,30,0,1,1,0,20
X,1, ,09/30/16 10:48:40,c,b,,r,,F,,,,,,
END
Y, ,09/30/16 10:48:40,c,1,.84054972,0,P,0,0,30,0,1,1,0,20
X,1, ,09/30/16 10:48:40,c,b,,r,,F,,,,,,
END
and i am splitting this file into many files depending on the string END. So in this case it will be splitted into two Files.
The name of the two splitted files are:
1.rslt.09-30-2016.10.17.43
1.rslt.09-30-2016.10.39.38
Now i want to take the bold part from the name of the file which is called date. and put it inside the splitted file in these locations
Y, ,Date,c,1,.84054972,0,P,0,0,30,0,1,1,0,20
X,1, ,Date,c,b,,r,,F,,,,,,
END
which means location 2 incase of the header and location 3 incase of normal line. I have the snippet for the split and while i am writting the file i am copying location 1 which has the value 1 into all upper columns. How can i write Date into locations 2 and 3 at the same time when i am writing the file?
The string date in the snippet is that date i want to put which is taken from the name of the file.
- var templines = File.ReadAllLines(SomeGlobalVariables.tempfilepath).ToList();
- int currentLine = 0;
-
-
- while (currentLine < templines.Count)
- {
- foreach (var date in dates)
- {
-
- int terminatorLine = templines.IndexOf("END-OF-LINE", currentLine);
- if (terminatorLine <= 0) break;
- int penultimateLine = terminatorLine - 1;
- var fields2 = templines[penultimateLine].Split(',');
-
- var fields3 = templines[penultimateLine-1].Split(',');
-
- name_1 = string.Format(@"C:\Users\{0}" + "." + "rslt" + "." + date, fields2[1]);
- if (fields2[0].Equals("X") && fields3[0].Equals("Y"))
- {
- fields2[3] = SwapCharacters(SwapCharacters(date.Replace("-", "/").Replace(".", ":").Remove(10, 1).Insert(10, " "), 6, 8), 7, 9).Remove(8, 2);
- fields3[2] = SwapCharacters(SwapCharacters(date.Replace("-", "/").Replace(".", ":").Remove(10, 1).Insert(10, " "), 6, 8), 7, 9).Remove(8, 2);
-
- Console.WriteLine(fields3[2]);
- }
-
-
- File.WriteAllLines(name_1, templines.Skip(currentLine).Take(terminatorLine - currentLine).Select(line => string.Join(",", line.Split(',').Select((text, index) => (index == 1) ? fields2[1] : text))));
-
- currentLine = terminatorLine + 1;
-
- }
-
- }