Hi

Need help reading data from a file after a specific point.
I need to read the data from this file into a richtextbox after the [HRData] header.


This is the contents of the file I'm reading from.

[Params]
Version=106
Monitor=34
SMode=111111100
Date=20100926
StartTime=08:45:59.0
Length=00:33:36.6
Interval=1
Upper1=0
Lower1=0
Upper2=0
Lower2=0
Upper3=180
Lower3=177
Timer1=00:00:00.0
Timer2=00:00:00.0
Timer3=00:00:00.0
ActiveLimit=0
MaxHR=195
RestHR=48
StartDelay=0
VO2max=54
Weight=0

[Note]

[IntTimes]
00:01:00.0	132	94	117	132
0	0	0	0	0	0
0	0	0	0	0
33554432	281	0	0	0	0
500	0	0	0	0	0
00:33:36.6	142	109	140	163
0	0	0	270	141	-126
0	0	0	0	0
0	10135	0	90	0	0
0	0	0	0	0	0
00:33:36.6	142	0	0	0
0	0	0	0	0	0
0	0	0	0	0
33554432	464	0	0	0	0
500	0	0	0	0	0

[IntNotes]

[ExtraData]

[Summary-123]
2016	0	2016	0	0	0
195	0	0	48
2016	0	2016	0	0	0
195	0	0	48
0	0	0	0	0	0
195	0	0	48
0	2016

[Summary-TH]
2016	0	2016	0	0	0
195	0	0	48
0	2016

[HRZones]
195
175
156
136
117
97
0
0
0
0
0

[SwapTimes]

[Trip]
168
0
2016
-118
-117
326
544
4308

[HRData]
97	117	0	-117	0	50
97	117	0	-117	0	50
97	183	0	-117	0	50
94	183	55	-117	34	50
95	210	56	-117	84	4931
95	207	59	-117	113	5438
95	196	57	-117	125	5944
97	248	56	-117	125	5944
98	255	64	-117	141	5432
100	252	64	-117	141	5432
101	248	79	-117	147	5444
102	237	82	-117	146	6456
104	235	82	-117	142	6457
105	247	84	-117	134	6458
106	261	87	-117	146	7220
106	268	87	-117	146	7220
107	281	91	-117	152	7475
108	292	95	-117	161	7733
109	297	98	-117	173	8245
110	301	101	-117	179	7733
111	299	103	-117	186	6966
112	297	106	-117	193	6445
113	294	105	-117	200	6706
115	293	104	-117	190	6703
116	294	103	-117	191	5685

I've got the file displaying in a richtextbox at the moment using this code.

private void button1_Click(object sender, EventArgs e)
        {
            

            string Chosen_File = "";

            openFile.Title = "Choose File";
            openFile.FileName = "";
            openFile.Filter = "HRM|*.hrm|Text Document|*.txt";
            openFile.ShowDialog();

            if (openFile.ShowDialog() != DialogResult.Cancel)
            {
                Chosen_File = openFile.FileName;
                richTextBox1.LoadFile(Chosen_File, RichTextBoxStreamType.PlainText);
            }

I just need to now show the data after the [HRData] header.
Any help would be great.

Hi,
You can use StreamReader to read rows, and the code will look like this:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            List<string> list = GetDataFromFile();
            richTextBox1.Clear();

            foreach (string item in list)
                richTextBox1.AppendText(item + Environment.NewLine);
        }

        private List<string> GetDataFromFile()
        {
            List<string> list = new List<string>();
            string tag = "[HRData]";
            bool bGetText = false;
            string path = @"C:\1\test17.txt";
            using (StreamReader sr = new StreamReader(path))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    if (bGetText)
                        list.Add(line);
                    else if (line == tag)
                        bGetText = true;
                }
            }
            return list;
        }
    }

The problem is, especially if you want to show numbers in some kind of columns, a better idea would be to use a datagriview - to seperate numbers. This is just an idea.

Mitja

Edited 5 Years Ago by Mitja Bonca: n/a

Btw, jsut in case:
that you would wonder where to get File class (add a new namespace: System.IO).
Mitja

Cheers for this info.

I was looking at doing a datagridview before but I have no knowledge of how to do it. Do you know of any online tutorials that I might be able to have a look at to help me?

This question has already been answered. Start a new discussion instead.