-
April 12th, 2011, 09:02 AM
#1
[RESOLVED] Delimiter while loop error!
Ive been attempting to complete a project which is due in a number of hours (yeah im an idiot leaving it this late) where I have to take information on properties.
Ive been trying to make a graph on how many times each county is entered. The information is stored on a text file with "," delimiters. Every 8th value should be the name of a county. The code ive been using is stated below:
using (StreamReader sr = new StreamReader("base.txt"))
{
while ((line = sr.ReadLine()) != null)
{
string[] delimiters = new string[] { "," };
while(delimiters[i] != null)
{
if(delimiters[i] == "Antrim")
{
antrimPoints++;
}
else if(delimiters[i] == "Armagh")
{
armaghPoints++;
}
else if(delimiters[i] == "Down")
{
downPoints++;
}
else if(delimiters[i] == "Fermanagh")
{
fermanaghPoints++;
}
else if(delimiters[i] == "LDerry")
{
lderryPoints++;
}
else if(delimiters[i] == "Tyrone")
{
tyronePoints++;
}
else
{
lostPoints++;
}
i = i + 8;
}
Console.WriteLine(line);
}
}
The error message I am getting it:
"IndexOutOfRangeException was unhandled." And the part highlighted is: while(delimiters[i] != null)
Is there something wrong with this statement? Im really struggling to get this form working. Gah, im such a programming newb.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|