0

Please can someone help me and send me in the right direction.
I am making a program that reads a text file and then out puts the data into a datagrid, the text file looks like this:

[HRData]
84    73    0   -124    0   50
84    73    0   -124    0   50
84    84    0   -124    0   50
87    109   0   -124    0   50
82    120   0   -124    0   50
82    132   0   -124    0   50
83    143   0   -124    0   50
83    154   0   -124    0   50
85    171   77  -124    0   50
86    179   84  -125    121 3893
87    190   84  -125    121 3893
88    193   93  -125    128 5423
90    201   96  -125    121 5932
91    206   100 -125    108 6446
92    212   100 -125    108 6446
93    217   103 -125    108 7469
94    215   99  -125    110 6700
94    214   84  -125    103 6957
93    211   70  -125    103 6957

This is only a section of the file as the content continues for a further 200 lines with different data.
Each column represents data from left to right "average_speed, top_speed,heart_rate, altitude, cadence, power"
I need to find a way to read all the data after the "[HRData]" header and then put them in an array or list of some kind so i can then use them in a datagrid.

ps. each row such as:

84  73  0   -124    0   50
84  73  0   -124    0   50
84  84  0   -124    0   50

is separated by a tab (\t) and of course each row is separated by a new line (\r\n)
I would love your professional knowledge to point me in the right direction

Required output:
array or list average_speed = 84,84,84,87,82,82,83,83,85,86,87,88,90,93,92,91,94,94,93
and so on...
Thank you

2
Contributors
1
Reply
32
Views
4 Years
Discussion Span
Last Post by Ketsuekiame
0

Open the file and create a StreamReader. Use ReadLine to pull each line from the file. On each line use Split and pass it \t as the delimiter argument. Add each result to a List<String> and then process the next line.

Alternatively, use ReadToEnd and try and split the entire thing in one go. Not sure if you'll have enough RAM to perform this kind of operation. Depends how big the file is.

Also, why did you mark the thread as solved before anyone answered? ;)

Edited by Ketsuekiame

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.