I need to read a textfile full of records. There is a header with several fields in the first two rows, after that the records are listed. Each record covers three rows. Every record consits of fields with fixed length. I’d like to fill a dataTable with the fields.
For example the file could look like:
header1 0101 2012
header2 0202 0000
rec10 abc
rec11 def
rec12 ghi
rec20 jkl
rec21 mno
rec22 pqr
For every field I’ve got the start and the length of the field.
I tried with StreamReader and substring, it’s working but it’s very akward.
Is there a better way to do this?
Using the FileHelpers library, your example could be parsed as follows:
Declare a class to represent your objects:
Load the data from the file like so: