Im writting a program that parses a specific text file that has data in it that im going to prcess later. Each part is seperated by a header in square brackets i was wondering how i could put each segment into an array using the header as a name for the array. Below is an example of the begining of the text file. ive set up a form that lets you choose a file you want to process and ive also set up a way of processing it line by line using objReader.ReadLine in a loop
[Params]
Version=106
Monitor=34
SMode=111111100
Date=20090725
StartTime=13:56:44.0
Length=00:24:30.5
Interval=1
Upper1=0
Lower1=0
Upper2=0
Lower2=0
Upper3=0
Lower3=0
Timer1=00:00:00.0
Timer2=00:00:00.0
Timer3=00:00:00.0
ActiveLimit=0
MaxHR=180
RestHR=70
StartDelay=0
VO2max=51
Weight=0
[Note]
TT Warm Up
[IntTimes]
00:24:30.5 140 83 154 174
0 0 0 41 112 33
0 0 0 0 0
0 12080 0 280 0 0
0 0 0 0 0 0
[IntNotes]
[ExtraData]
[Summary-123]
1470 0 1470 0 0 0
180 0 0 70
1470 0 1470 0 0 0
180 0 0 70
0 0 0 0 0 0
180 0 0 70
0 1470
[Summary-TH]
1470 0 1470 0 0 0
180 0 0 70
0 1470
[HRZones]
180
162
144
126
108
90
0
0
0
0
0
I'd parse it into a dictionary:
The above approach will also append data lines if you have duplicate tokens.
You could use a pattern something like this.
I'm not quite sure how you mean to use the header as a name for the array. Are the headers always the same for all of the files? You can't dynamically allocate the name of a variable based on a string, nor would you want to if you need to use it in later processing.
Since this file format goes beyond a normal INI file (see comment by David Yaw in Nicholas Carey's answer) I'd use a proper parser created by a parser generator. My tool of choice is the GOLD Parser Builder, but any other parser generator may do just as well.