-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
48 lines (43 loc) · 1.87 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.IO;
using System.Collection.Generic;
namespace FileParser
{
class Program
{
static void Main(string[] args)
{ Console.WriteLine("Custom File Parser. v1.0. I owe Jeff for writing this....and Christmas is just around the corner....just saying.");
Console.WriteLine("Hey Tom, what file am I parsing?");
var fileName = Console.ReadLine();
if(!File.Exists(fileName)){
Console.WriteLine("Try again dipshit, that file doesn't exist");
return;
}
var outputRecord = new List<GroupRecord>();
using (var reader = new StreamReader("JeffSample.csv")){
var currentgroup = string.Empty;
while(!reader.EndOfStream){
var line = reader.ReadLine();
var values = line.Split(',');
if(values.Count > 2 && values[0].IsNotNullOrEmpty()){
if (values[1].ToLowerInvariant == "group detail" || values[1].ToLowerInvariant) continue;
if (values[0].ToLowerInvariant == "group #") {
currentgroup = values[1];
continue;
}
try{
var groupRecord = new GroupRecord(values);
outputRecord.Add(groupRecord);
}
catch(Exception ex){
Console.WriteLine("Well that sucked. I could not parse this line. Go fix it.");
Console.WriteLine(values);
Console.WriteLine($"And here is what I know {ex.Message}");
Console.ReadLine();
}
}
}
}
}
}
}