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

  • Home
  • SEARCH
  • 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 7565679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:12:59+00:00 2026-05-30T14:12:59+00:00

I need to read a textfile full of records. There is a header with

  • 0

I need to read a textfile full of records. There is a header with several fields in the first two rows, after that the records are listed. Each record covers three rows. Every record consits of fields with fixed length. I’d like to fill a dataTable with the fields.

For example the file could look like:

header1 0101 2012
header2 0202 0000
rec10 abc 
rec11 def
rec12 ghi
rec20 jkl
rec21 mno
rec22 pqr

For every field I’ve got the start and the length of the field.

I tried with StreamReader and substring, it’s working but it’s very akward.

Is there a better way to do this?

  • 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-30T14:13:01+00:00Added an answer on May 30, 2026 at 2:13 pm

    Using the FileHelpers library, your example could be parsed as follows:

    Declare a class to represent your objects:

    [IgnoreFirst(2)]
    [FixedLengthRecord(FixedMode.ExactLength)]
    public sealed class Record
    {
        [FieldTrim(TrimMode.Right)]
        [FieldFixedLength(6)]
        public String Header1;
    
    
        [FieldFixedLength(3)]
        public String Data1;
    
        [FieldInNewLine()]
        [FieldTrim(TrimMode.Right)]
        [FieldFixedLength(6)]
        public String Header2;
    
        [FieldFixedLength(3)]
        public String Data2;
    
        [FieldInNewLine()]
        [FieldTrim(TrimMode.Right)]
        [FieldFixedLength(6)]
        public String Header3;
    
        [FieldFixedLength(3)]
        public String Data3;
    }
    

    Load the data from the file like so:

    FileHelperEngine<Record> engine = new FileHelperEngine<Record>();
    
    engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;
    
    DataTable records = engine.ReadFileAsDT(@"myTextFile.txt");
    
    if (engine.ErrorManager.ErrorCount > 0)
        engine.ErrorManager.SaveErrors("Errors.txt");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two different models that need saving; a TextFile object and a static
I have a textfile that I need to read into matlab. I want to
i have a remote text file on http://somewhere ... that i need to read
I make android application that read textfile.txt from resource/raw. And it's work fine. Here
hi I need to read a text file and then explode it to two
I need to develop an application that will read and understand text file in
I need to read the nth line of a text file (e.g. textfile.findline(0) would
I need to read in a file that contains 2 sentences to compare and
I need to read char[] (size is COUNT) from text file from OFFSET with
I need to read test.TXT file(tab delimited) into MATLAB. TXT file have form: Datum

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.