Hello

I am currently trying to read specific data from a .hrm file and then display it within a form in c#. For example I want to read the date data from this file and then display it on the form. All I have managed to do is read in the whole file into a textbox. I've been struggling with this for a while now and would appreciate any help I can get.

This is the code I have so far that reads the whole file into the richtextbox.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;


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

        

        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);
            }

            

        }


    }
}

This is the file I want to retrieve the data from.

[Params]
Version=106
Monitor=34
SMode=111111100
Date=20100926
StartTime=09:20:11.0
Length=01:06:11.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=70

I am trying to get the Date data after the = sign.

Any help would be appreciated, thank you.

Here is a sample program that will get you all the values that start with Date:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace TestBed {
    class Program {
        static void Main(string[] args) {
            String[] lines = File.ReadAllLines("test.txt"); // Read all the lines into an array

            IEnumerable<String> date = from n in lines            // go through all the lines
                                       where n.StartsWith("Date") // filter those that begin with "Date"
                                       select n.Split('=')[1];    // return just the info after the '=' sign

            foreach (String d in date) {
                Console.WriteLine(d);
            }
           
            Console.ReadLine();
        }
    }
}

This solved the problem with a bit of editing, thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.