Advertisement
Guest User

Domaci

a guest
Apr 5th, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1.         public List<Line> Parse()
  2.         {
  3.             try
  4.             {
  5.                 using (StreamReader Reader = new StreamReader(PATH))
  6.                 {
  7.  
  8.                     List<Line> Lines = new List<Line>();
  9.  
  10.                     Regex Trim = new Regex(@"SMER:");
  11.                     Regex Direction = new Regex(@".*SMER:\s*([^\n\r]*)");
  12.                     Regex Time = new Regex(@"\d{2}:\d{2}");
  13.  
  14.                     while (!Reader.EndOfStream)
  15.                     {
  16.                         string line = Reader.ReadLine();
  17.  
  18.                         if (!String.IsNullOrWhiteSpace(line))
  19.                         {
  20.                             if (Direction.IsMatch(line))
  21.                             {
  22.                                 Lines.Last().Directions.Add(new Direction(Trim.Replace(line, ""), new List<string>()));
  23.                             }
  24.                             else if (Time.IsMatch(line))
  25.                             {
  26.                                 Lines.Last().Directions.Last().Times.Add(line);
  27.                             }
  28.                             else
  29.                             {
  30.                                 Lines.Add(new Line(line, new List<Direction>()));
  31.                             }
  32.                         }
  33.                     }
  34.                     return Lines;
  35.                 }
  36.             }
  37.             catch (Exception e)
  38.             {
  39.                 Console.WriteLine(e);
  40.                 throw;
  41.             }
  42.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement