If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

[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:

Re: Delimiter while loop error!

Ok. Try this out

Code:

//Indicate what position in each line the county appears in
const int COUNTY_INDEX = 1;
//Prepare our delimiter
char[] delimiter = new char[] { ',' };
//Prepare our dictionary for storing a count for each county
Dictionary<string, int> countyCount = new Dictionary<string, int>();
using (StreamReader sr = new StreamReader("base.txt"))
{
do
{
//Extract the next line from the file
//and pull out the county
string line = sr.ReadLine();
string[] parts = line.Split(delimiter);
string county = parts[COUNTY_INDEX];
//Make a note of the count for this county
if (countyCount.ContainsKey(county))
{
countyCount[county]++;
}
else
{
countyCount.Add(county, 1);
}
} while (!sr.EndOfStream);
}
foreach (KeyValuePair<string, int> county in countyCount)
{
string name = county.Key;
int number = county.Value;
//***** Now do what you like with name and number
}

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.