以下のようなcsvファイルがあります。
Processname:;ABC Buying
ID:;31
Message Date:;08-02-2012
Receiver (code):;12345
Object code:
Location (code):;12345
Date;time
2012.02.08;00:00;0;0,00
2012.02.08;00:15;0;0,00
2012.02.08;00:30;0;0,00
2012.02.08;00:45;0;0,00
2012.02.08;01:00;0;0,00
2012.02.08;01:15;0;0,00
上記のメッセージが 1 回以上発生する可能性があるため、2 回発生した場合、csv ファイルは次のようになります...
Processname:;ABC Buying
ID:;31
Message Date:;08-02-2012
Receiver (code):;12345
Object code:
Location (code):;12345
Date;time
2012.02.08;00:00;0;0,00
2012.02.08;00:15;0;0,00
2012.02.08;00:30;0;0,00
2012.02.08;00:45;0;0,00
2012.02.08;01:00;0;0,00
2012.02.08;01:15;0;0,00
Processname:;ABC Buying
ID:;41
Message Date:;08-02-2012
Receiver (code):;12345
Object code:
Location (code):;12345
Date;time
2012.02.08;00:00;0;17,00
2012.02.08;00:15;0;1,00
2012.02.08;00:30;0;15,00
2012.02.08;00:45;0;0,00
2012.02.08;01:00;0;0,00
2012.02.08;01:15;0;9,00
このcsvファイルを解析する最良の方法は何ですか?
私のアプローチの疑似コード...
// Read the complete file
var lines = File.ReadAllLines(filePath);
// Split the lines at the occurrence of "Processname:;ABC Buying"
var blocks = lines.SplitAtTheOccuranceOf("Processname:;ABC Buying");
// The results will go to
var results = new List<Result>();
// Loop through the collection
foreach(var b in blocks)
{
var result = new Result();
foreach(var l in b.lines)
{
// read the first line and check it contains "Processname" if so, assign the value to result.ProcessName =
// read the 2nd line and check it contains "ID" if so, assign the value to result.ID
// read the 3rd line and check it contains "Object Code" if so, assign the value to result.ObjectCode
// Ignore string.empty
// check for location (code), if so assign the value to result.LocationCode
// Parse all the other rows by spliting with ';' the first part is date, 2nd part is time, 3rd part is value
}
results.Add(result);
}
これを行う最良の方法は何ですか?