I need to parse a file but the data is in a strange format that I'm not familar parsing.
The data is always formatted like this. The field name is to the left and the data is right of the "=" and all fields are always in this order.
File Data:
Report 1 of 1
job_name = JOBNAME
job_no = JOB99999 job_id = 6750
rprt_id = 27811
rprt_name = SOMEDATA.SOMEUSER.JOBNAME.JOB099999.0000000.?
ftp_size = 999999
job_group_name = 1
clas = Z
form = 9999
user_id = SOMEUSER
My first instinct is to do something like this...
'New up a class created to hold the data'
Dim NFOData As New NFOData
'Create counter for line numbers'
Dim i As Integer = 1
Using sr As New StreamReader(filename)
While Not sr.EndOfStream
Dim line As String = sr.ReadLine
Select Case i
Case 2
NFOData.JobName = line.Substring(11)
Case 3
NFOData.JobNo = line.Substring(9)
Case 4
'snipped to save space'
End Select
i += 1
End While
End Using
This doesn't seem very clean or elegant to me.
Is there a more elegant way to handle parsing files like this?