There is a file with 1000 lines, a comma separator in the line, the numbers in the second position are: 01.02.03.03.04.05.06. It is necessary to calculate how much was 01,02,03,04,05,06?
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Text.RegularExpressions; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { //Создание папки и подпапок DirectoryInfo papka = new DirectoryInfo(@"C:\Users\a.filatov\Desktop\Test\"); try { papka.CreateSubdirectory(@"Writer"); papka.CreateSubdirectory(@"Incorrect"); } catch (IOException e) { Console.WriteLine(e.Message); } //Путь к файлу string path = @"C:\Users\a.filatov\Desktop\1\COMMA.txt"; //Читаем текст в файле построчно string[] readText = File.ReadAllLines(path); //Объявляем интервал времени TimeSpan intervaltimesum = new TimeSpan(); //Текущее время в элементе массива TimeSpan current_time; //Счётчик int countTime = 0; //Создание потока для записи в файл StreamWriter W = new StreamWriter(@"C:\Users\a.filatov\Desktop\Test\Writer\Write.txt"); StreamWriter A = new StreamWriter(@"C:\Users\a.filatov\Desktop\Test\Incorrect\Incorrect.txt"); //Цикл для считывания строк for (int i = 19; i < 1019; i++) { //Установка разделителем массива запятой string[] elements = readText[i].Split(','); //Если четветрый элемент в строке существует, то работаем с ним if (elements.GetLength(0) > 4) { //Разбор 4 элемента массива try { //Разделитель ":" string[] times = elements[4].Split(':'); int hours = int.Parse(times[0]); int minutes = int.Parse(times[1]); int seconds = int.Parse(times[2]); current_time = TimeSpan.FromHours(hours) + TimeSpan.FromMinutes(minutes) + TimeSpan.FromSeconds(seconds); // Запись в файл W.WriteLine("{0} {1} {2} \t\t Текущее время = {3} Общее время = {4}", i - 18, elements[0], elements[4], current_time, intervaltimesum); //Вывод 4 элемента массива в файл if (current_time.TotalHours > 2) { // в отдельный файл выведем значение более 2-х часов A.WriteLine("{0}", current_time); } else { // если меньше двух часов - тогда суммируем intervaltimesum += current_time; countTime++; } } catch (Exception) { throw; } } } //Закрытие потока A.Close(); //Вывод среднего времени в нужном формате TimeSpan intervalAverage = TimeSpan.FromSeconds(intervaltimesum.TotalSeconds / countTime); Console.WriteLine("Среднее время = {0:hh\\:mm\\:ss}", intervalAverage); //Запись в файл времени W.WriteLine("\n\n Всё время отклонения = {0} в секундах = {1}", intervaltimesum, intervaltimesum.TotalSeconds); //Запись среднего времени W.WriteLine(" Среднее время {0:hh\\:mm\\:ss}", intervalAverage); W.Close(); } } }