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 9011381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:42:48+00:00 2026-06-16T02:42:48+00:00

I’m running three counters, one to return the total amount of chars, one to

  • 0

I’m running three counters, one to return the total amount of chars, one to return the number of ‘|’ chars in my .txt file (total). And one to read how many separate lines are in my text file. I’m assuming my counters are wrong, I’m not sure. In my text file there are some extra ‘|’ chars, but that is a bug I need to fix later…

The Message Boxes show  
"Lines = 8"   
"Entries = 8"   
"Total Chars = 0"  

Not sure if it helps but the .txt file is compiled using a streamwriter, and I have a datagridview saved to a string to create the output. Everything seems okay with those functions.

Here is a copy of the text file I’m reading

Matthew|Walker|MXW320|114282353|True|True|True  
Audrey|Walker|AXW420|114282354|True|True|True    
John|Doe|JXD020|111222333|True|True|False  
||||||  

And here is the code.

    private void btnLoadList_Click(object sender, EventArgs e)
    {
        var loadDialog = new OpenFileDialog
            {
                InitialDirectory = Convert.ToString(Environment.SpecialFolder.MyDocuments),
                Filter = "Text (*.txt)|*.txt",
                FilterIndex = 1
            };
        if (loadDialog.ShowDialog() != DialogResult.OK) return;
        using (new StreamReader(loadDialog.FileName))
        {
            var lines = File.ReadAllLines(loadDialog.FileName);//Array of all the lines in the text file
            foreach (var assocStringer in lines)//For each assocStringer in lines (Runs 1 cycle for each line in the text file loaded)
            {
                var entries = assocStringer.Split('|'); // split the line into pieces (e.g. an array of "Matthew", "Walker", etc.)
                var obj = (Associate) _bindingSource.AddNew();
                if (obj == null) continue;
                obj.FirstName = entries[0];
                obj.LastName = entries[1];
                obj.AssocId = entries[2];
                obj.AssocRfid = entries[3];
                obj.CanDoDiverts = entries[4];
                obj.CanDoMhe = entries[5];
                obj.CanDoLoading = entries[6];
            } 
      }
   }

Hope you guys find the bug(s) here. Sorry if the formatting is sloppy I’m self-taught, no classes. Any extra advice is welcomed, be as honest and harsh as need be, no feelings will be hurt.

In summary

Why is this program not reading the correct values from the text file I’m using?

  • 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-06-16T02:42:49+00:00Added an answer on June 16, 2026 at 2:42 am

    Not totally sure I get exactly what you’re trying to do, so correct me if I’m off, but if you’re just trying to get the line count, pipe (|) count and character count for the file the following should get you that.

    var lines = File.ReadAllLines(load_dialog.FileName);
    int lineCount = lines.Count();
    int totalChars = 0;
    int totalPipes = 0; // number of "|" chars
    
    foreach (var s in lines)
    {
        var entries = s.Split('|');  // split the line into pieces (e.g. an array of "Matthew", "Walker", etc.)
        totalChars += s.Length;   // add the number of chars on this line to the total
        totalPipes = totalPipes + entries.Count() - 1; // there is always one more entry than pipes
    }
    

    All the Split() is doing is breaking the full line into an array of the individual fields in the string. Since you only seem to care about the number of pipes and not the fields, I’m not doing much with it other than determining the number of pipes by taking the number of fields and subtracting one (since you don’t have a trailing pipe on each line).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.