Reading Lines from a file

Posted on 2006-06-05
Last Modified: 2012-05-05
Here is my code so far:

private void btnFile_Click(object sender, System.EventArgs e)
      string scores = "";
      string dir = @"C:\C#.NET\Files\";

      string path = dir + "studentlist.txt";
      StreamReader textIn = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read));

      ArrayList dummies = new ArrayList();
      while(textIn.Peek() != -1)
            string row = textIn.ReadLine();
            string[] columns = row.Split('|');
            int x = 1;

--->            while(columns[x] != null)
                  scores += columns[x].ToString();

            Student student = new Student(columns[0], columns[1]);
      //      student.Name = columns[0];
      //      student.Scores = columns[1];

                  foreach(object s in dummies)


I want the parser to read the line, which is in the format of "Someone's Name|54|65|76|76". So for column[0] we have the name, and columns[1] and higher (number can vary), we have the scores. In the line of code indicated, how do I make the parser read through all the columns in the line after the 0th column? I can't quite get it working.

I can only get the listbox to display "Someones Name|44", but I need to display all the numbers after that too.

Question by:igor92128
    LVL 2

    Expert Comment

    instead of

    --->          while(columns[x] != null)
                   scores += columns[x].ToString();

    write this:

    foreach(string s in columns)
        scores += s;
    LVL 85

    Accepted Solution

    "how do I make the parser read through all the columns in the line after the 0th column?"

    So you want to skip the first element?...

                for (int i = 1; i < columns.Length; i++)
                    scores += columns[i];

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    In one of my recent projects, I was working with IP cameras, I need to take some pictures from the camera and do some processing on it. The first step, was to retrieve the image from camera into Image object. So that it can be displayed or …
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now