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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:21:42+00:00 2026-05-24T05:21:42+00:00

I am trying to get the second value from a CSV file with 100

  • 0

I am trying to get the second value from a CSV file with 100 rows. I am getting the first 42 values then it stops… no error messege, or error handling at all for that matter. I am perplexed and am on a timeline. It is also doing it for a TSV file, but giving the first 43 results. Please help and let me know if it looks strange to you.

I am using streamreader, reading each line into a string array, splitting the array and taking the second value and adding it to a list…

        string path = @"C:\Users\dave\Desktop\codes\testfile.txt";
        StreamReader sr = new StreamReader(path);
        List<string> stkno = new List<string>();

        foreach (var line in path)
        {
            string s = sr.ReadLine();
            string[] words = s.Split(',');
            stkno.Add(words[1]);
        }
        var message = string.Join(",", stkno.ToArray());
        MessageBox.Show(message);
  • 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-24T05:21:42+00:00Added an answer on May 24, 2026 at 5:21 am

    Your path variable is a string. That means when you foreach over it, you’re getting a sequence of characters – ‘C’ then ‘:’ then ‘\’ etc. I don’t think that’s what you mean to do…

    Here’s a simpler approach using File.ReadLines:

    string path = @"C:\Users\dave\Desktop\codes\testfile.txt";
    
    List<string> stkno = (from line in File.ReadLines(path)
                          let words = line.Split(',')
                          select words[1]).ToList();
    

    Or:

    string path = @"C:\Users\dave\Desktop\codes\testfile.txt";
    
    List<string> stkno = File.ReadLines(path)
                             .Select(line => line.Split(',')[1])
                             .ToList();
    

    If you’re using .NET 3.5 and you don’t mind reading the whole file in one go, you can use File.ReadAllLines instead.

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

Sidebar

Related Questions

I am trying to create a dictionary from a csv file. The first column
The second echo below throws the error Trying to get property of non-object? The
I am trying to get the value from the radio boxes/button with php. The
in my app i am trying to get an xml file from an URL.
I am trying to get the value from the checkbox selected in a form
I am trying to get all values (except corresponding to a particular key) from
I was trying to retrieve value from two tables by joining, but few values
I am just trying to get the auto incremented value of a table that
I'm trying to get a timer to tick once a second in a winform,
just been trying to recieve the session value from multiple jquery ajax requests on

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.