Parser.cs 751 B

123456789101112131415161718192021222324252627
  1. using System.Text.RegularExpressions;
  2. namespace Day12;
  3. public partial class Parser
  4. {
  5. [GeneratedRegex(@".*")]
  6. private partial Regex LineMatch();
  7. public IEnumerable<WellRecord> Parse(string inputFile)
  8. {
  9. using var reader = File.OpenText(inputFile);
  10. while (!reader.EndOfStream)
  11. {
  12. var line = reader.ReadLine()!;
  13. var parts = line.Split(' ');
  14. yield return new WellRecord(
  15. parts[0],
  16. parts[1]
  17. .Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)
  18. .Select(x => int.Parse(x))
  19. .ToArray()
  20. );
  21. }
  22. }
  23. }