0

Alright. I'm having a problem. I have to load student data from text files, and put them into a class called Students.

So far-

const string STUDENT_FILE = @"C:Users\Etc\Etc\Students.txt";
Students students = File.Routines.LoadStudents(STUDENT_FILE)

Then my class FileRoutines uses it's method

static public string [] LoadStudents(string STUDENT_FILE)

To read the file line by line and create a string array for each line. (this is what I have so far, I wasn't given very much to work with.)

string[] students  = File.ReadAllLines(STUDENTS_FILE);

The instructions say that I have to "read all lines in the student input file, create a student object from each line. return a Students object that contains an array of the Students objects.

And by the end of it all, that array is supposed to end up in the Students class. I'm supposed to also do a .Split('\t') on the students array and split it up into 3 more arrays.

The file that I'm working with has data set up as so. 122338 Weltzer Teresa 123123 Wang Choo 123131 Adams James 123132 Binkley Joshua 123139 Howard Tyler 123160 King Alma

After all the code, it's supposed to have 3 string arrays.

studentID[]
lastName[]
firstName[]

I know this is kinda of ridiculous, and I'm asking a lot. But I have looked everywhere, and I can't figure out how to do it. I've seen how to do it other ways, but I was asked to do it this specific way. If I can clarify anything more for y'all, or if I need to add something to let me know. This is my first post, so go easy. Thanks!

Adam Cole
  • 1
  • 1
  • I don't see question mark in that entire question. You might try asking a specific question and adding some examples of what you've tried. – Joey Gennari May 02 '13 at 15:56

2 Answers2

0
List students = new List();
string[] splitData = students.split[" "];
int i = 0;
foreach(string s in splitData)
{
    var student = new Student();
    student.StudentId = splitData[i++];
    student.FirstName = splitData[i++];
    student.FirstName = splitData[i++];
    students.Add(student);
}

Does that help?

gwin003
  • 7,432
  • 5
  • 38
  • 59
0

The instructions say that I have to "read all lines in the student input file, create a student object from each line. return a Students object that contains an array of the Students objects

Where is your definition for Class Student()? <-- holds ID, LastName, FirstName

Where is your definition for Class Students()? <-- holds an Array of Class Student

To process the lines in the file, you'd do something like:

        string[] students = File.ReadAllLines(STUDENTS_FILE);
        foreach (string studentData in students)
        {

            // ... do something in here with "studentData" ...

        }

The "something" in the loop would be something like what @gwin003 posted.

Idle_Mind
  • 38,363
  • 3
  • 29
  • 40