I can't belive, the easiest task won't work!
I just want to loop through a csv file by using the StreamReader-Class and find a key in a associative line. e.g.:
- key1;value1
- key2;value2
- key3;value3
If the key exists, no problems. Otherwise EOF should be reached, but it does not work!
If I discard the buffered data, EOF will be reached everytime. In result no key will be found.
Edit: with all the suggestions, but same result!
StreamReader reader = null;
if(!string.IsNullOrEmpty(textBox1.Text))
{
try
{
reader = new StreamReader(@"ident.csv", Encoding.ASCII);
string buffer;
string[] str = null;
while((buffer = reader.ReadLine()) != null)
{
if(buffer.Contains(";"))
{
str = buffer.Split(';');
if(str[0].Equals(textBox1.Text))
break;
}
}
if(reader == null)
{
MessageBox.Show("Ident not found!");
textBox2.Text = "";
}
else
{
textBox2.Text = str[1];
Clipboard.SetText(str[1]);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
reader.Dispose();
reader.Close();
}
}
else
{
MessageBox.Show("Set ident!");
}
}