matthew king

matthew king

  • NA
  • 47
  • 0

Streamreader, .txt file

Mar 26 2010 9:45 PM

Sir/Ma'am
I have a .txt file int the following format:
[test1]
blue 
red
green
[test2]
one 
two
three
[test3]
white 
black
grey

I'm trying to read the everything below [test2] and above [test3] into a combobox.  So, I'm trying to populate comboBox1 with one, two, and three.  I thought this might work, but I was wrong:
{
comboBox1.Items.Clear();
using (StreamReader sr = new StreamReader(@"c:\test.cfg"))
{
String line1;
do
{
line1 = sr.ReadLine();
if (line1.StartsWith("[test2"))
{
line1 = line1.Split(
']')[1].Trim();
String[] strgArray;
strgArray = line1.Split(
'\n');
foreach (String strg in strgArray)
{
comboBox1.Items.Add(strg.Trim());
}
break;
}
}
while ((line1 != null));
Console.Read();
}
}
}

THANK YOU!!! 

Answers (4)