Hi all, first time posting in here so hope i don't mess it up.
Very new to programming, C# / .NET, and currently in my first few weeks of an internship of sorts.
Not sitting in front of my code so might have to use a little pseudo code here, apologies.
I've been assigned a little project to build an app that finds the file paths of all text files in a given destination folder plus all root folders and loads them to an array.
It then needs to cycle through this array, read each text file and lastly build a table. All text files are in this format:
Code:
Fname: John
Sname: Smith
Age: 25
ID: 123
Ref: R11
Date: 01022013
Fname: Paul
Sname: Smith
Age: 28
ID: 143
Ref: R12
Date: 01052013
Fname: Brian
Sname: Jones
Age: 25
ID: 223
Ref: R23
Date: 01022011
.....
I have the methods build to load the array with file paths and built a method to split the contents of each file using Regex.split ": ". This gives me an array "string [] wordList", containing basically a list of each word like so:
Code:
Fname
John
Sname
Smith
Age
25
ID
123
Ref
R11
Date
01022013
...
Ive created a data table with the six headings and am now trying to access the relevant elements of the array, assign them to local variables and then add a row to the table. Tried using a switch first, then a for loop:
Code:
String fname;
String sname;
String age;
String id;
String ref;
String date;
for (int i=1; i<=11 && i<=wordList.Lenght; i+=2)
{
if(i==1)
{
fname = wordList[i];
}
else if(i==3)
{
sname = wordList[i];
}
......
//add row to table (fname, sname, age,.....)
i=1;
}
This throws an exception after the first if statement.
Am I going about this all wrong? ie should I be loading the table totally differently (what should I be googling
). If not can anyone tell me what's wrong with my loop?
Apologies for the TLDR, thought it best to give as much info as possible.
Any replies greatly appreciated