this Kind of Thing is my daily bread and butter. is the size of the Header(fluff) always the same Count of lines? If so, use a StreamReader, Count the lines you're reading until you reach the data. As I understand it, every line of the data represents a different Meter with its own data, the strucure is always the same with the same count of elements and the same Positions. If so, read the lines of Data into an Array of string. from then on you can do with the seperate fields as you like as Long as you know the Position, for example date is alway on the first Position, in a Array this means it is on Position '0'.
private void readLines(string inputFile, int headerLineCount)
{
List inputList = new List();
Encoding coding = Encoding.GetEncoding(1252); //Ansi-Encoding, Change to 850 for ASCII, 1200 for Unicode UTF16, 65001 for UTF8 etc.
StreamReader reader = new StreamReader(inputFile, coding);
int lineIndex = 0;
while (reader.EndOfStream != true)//Read until the file has no more lines to read.
{
string inputLine = reader.ReadLine();//read the data here
if (lineIndex >= headerLineCount)//This Code is executed only after the set amount of lines (header) has been overread.
{
string\[\] inputElements = inputLine.Replace("\\"", "").Split(','); //We replace the '"' with an empty string and split the line into seperate Elements. You can use any char as a delemiter, for excample ';' or '!' etc.
meterInput newInput = new meterInput();
newInput.Date = Convert.ToDateTime(inputElements\[0\]);// Here we use the first element of the 'inputElements' and convert it to a Datetime.
newInput.Name = inputElements\[1\];
newInput.HE1 = Convert.ToDecimal(inputElements\[2\]);
newInput.HE2 = Convert.ToDecimal(inputElements\[3\]);
newInput.HE3 = Convert.ToDecimal(inputElements\[4\]);
newInput.HE4 = Convert.ToDecimal(inputElements\[5\]);
//... Add the rest of the data.
newInput.OnPeak = Convert.ToDecimal(inputElements\[26\]);
newInput.OffPeak = Convert.ToDecimal(inputElements\[27\]);
newInput.Total = Convert.ToDecimal(inputElements\[28\]);
inputList.Add(newInput); // Add the complete element to