Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 905911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:18:00+00:00 2026-05-15T16:18:00+00:00

I need some logic/programming help with reading more than one record from a text

  • 0

I need some logic/programming help with reading more than one record from a text file. I can read line for line, but I need to stop as soon as the record is finished, push that object to a list, and then continue with a new record until the next one comes up, save to list, etc…

The header of the record always start with G as the first char. The rest if V (Variable), D (Coordinates), M (Insertion Point), etc…

The file contents looks like this: (dummy data)

G FEATURE01 LEVEL01
M -10.5132 10.0000 697.5086
V \~\@ENTITY=LINE 
V \~\@PENSTYLE=0
V \~\@PENTHICK=1
D -10.5089 12.0797 697.8155
D -10.4971 13.6198 698.0429
D -10.0399 17.3069 698.5913
D -10.7665 11.6108 699.2279
D -10.6769 15.9840 699.8735
D -10.8229 13.6024 710.4438
G FEATURE02 LEVEL02
M -10.2681 10.0000 700.4186
V \~\@ENTITY=LINE
V \~\@PENSTYLE=0
V \~\@PENTHICK=1
D -10.2269 10.6946 700.4941
D -10.2585 13.1788 700.7637
D -10.2937 15.9480 701.0642
D -10.9494 20.5230 709.1840
D -10.9277 21.4909 709.4517
D -10.8335 23.3862 709.9763
G FEATURE01 LEVEL02
M -15.4500 10.0000 700.4174
V \~\@ENTITY=LINE 0.00 0 0.00 A A
V \~\@PENSTYLE=0 0.00 0 0.00 A A
V \~\@PENTHICK=1 0.00 0 0.00 A A
D -15.5690 12.3042 700.6673
D -15.3502 14.3130 700.8863
D -15.1219 16.7179 701.1480
D -15.0628 17.3409 701.2427
D -15.5481 20.8968 709.2855
D -15.3132 22.9163 709.8470
D -15.1355 23.2957 709.9627
G FEATURE03 LEVEL03
P 0.0000 0.0000 0.0000 270.0000 90.0000
M -12.8612 14.2951 737.6336
V \~\@ENTITY=LINE
V \~\@PENSTYLE=1
V \~\@PENTHICK=1
V @0ver1ay=KOOS
D -13.2715 15.5321 736.5965

So, as from above there is 4 records in the text file.
Any ideas?
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:18:01+00:00Added an answer on May 15, 2026 at 4:18 pm

    Here is a piece of code that I have tried to put together for clarity rather than robustness etc. it should put you on the right track.

    1- I created a simple record class which will be created for each record (lines starting with ‘G’) and then all subsequent lines are added to this record until a new start of record is encountered in the file.

    class Record
    {
      public List<string> Lines { get; private set; }
      public Record()
      {
        Lines = new List<string>();
      }
    }
    

    2- Then the following code will process the file line by line, creating new records as they occurr and adding each record to a Record collection.

      // Collection to be populated with the record data in the file
      List<Record> records = new List<Record>();
    
      using (FileStream fs = new FileStream("datafile.dat", FileMode.Open))
      using (StreamReader rdr = new StreamReader(fs))
      {
        string line;
    
        // Read first line
        line = rdr.ReadLine();
        while (line != null)
        {   
          // Check if we have a new record
          if (line.StartsWith("G"))
          {
            // We have a start of a record so create an instance of the Record class
            Record record = new Record();
    
            // Add the first line to the record
            record.Lines.Add(line);
    
            // Read the next line
            line = rdr.ReadLine();
    
            // While the line is not the start of a new record or end of the file,
            // add the data to the current record instance
            while (line != null && !line.StartsWith("G"))
            {
              record.Lines.Add(line);
              line = rdr.ReadLine();
            }
    
            // Add the record instance to the record collection
            records.Add(record);
          }
          else
          {
            // If we get here there was something unexpected
            // So for now just move on and read the next line
            line = rdr.ReadLine();
          }
        } 
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 493k
  • Answers 493k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I've probably not understood what you're trying to do, but… May 16, 2026 at 10:54 am
  • Editorial Team
    Editorial Team added an answer Choose type of iterator which fits your container: input, output,… May 16, 2026 at 10:54 am
  • Editorial Team
    Editorial Team added an answer I managed to get it converted correctly for VB 2008… May 16, 2026 at 10:53 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I need help with some programming logic... I need to loop this method to
i need some help understanding how i can create a new custom event. i
While reading SICP I came across logic programming chapter 4.4. Then I started looking
I have some logic whereby a graph of POCO entities need to be cloned
I need some help with a query - I'm using Firebird 2.1. I have
I'm a fairly new programmer and very new to web programming and I need
First of all, I need to say that my English is not good. So
sry about my english :) Im new to Java programming and i have a
I'm planning to write my first program (it'll be in C#), and I need
I am new to the locating hardware side of embedded programming and so after

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.