Hi, I am trying to figure out the best way to parse this comma delimited text file. Here is an excerpt:
bldgA, fred, lunch bldgA, sally, supper bldgB, bob, parking lot bldgB, frank, rooftop ...
What I am trying to do is read "bldgA" and then I want the person (2nd column), "fred" for example. But I don't want to parse the file looking for "fred" because fred may not be there next time whereas bldgA always will be. I want to read the text file, see that I am on bldgA, and read the next item in my list which is fred. After that I want to test if it is fred, sally, etc.and print out the third column. I know this might be easier with a database but seems to be a bit of overhead for a small text file just so I can name columns. Before I resorted to Access or something small, I thought I'd try stackoverflow. Here is what I have:
string BuildingFile = Server.MapPath("buildings.txt");
StreamReader FileStreamReader;
FileStreamReader = File.OpenText(BuildingFile);
while (FileStreamReader.Peek() != -1)
{
string[] words;
words = FileStreamReader.ReadLine().Split(',');
foreach (string word in words)
{
if (word == "bldgA")
{
//but since word is only on "bldgA"
//how can I get the next item in the list which
//is on the same line?
//print out the name of the person and then the duty
}
if (word == "bldgB")
{
//same as A
}
}
}
FileStreamReader.Close();
My final output would be
"You are in bldgA and your name is fred and your duty is lunch"
Thank you.