I have a text file which I split with a \n.
text file (test) reads
1
2
3
4
now the confusing part.
code
string test = System.IO.File.ReadAllText(@"C:\Custom tests\"+testselect.Text+".txt");
string[] check = test.Split('\n');
if (check[0] == "1")
{
label.Text = "whatever";
}
this does not work. The label stays default value. however if I :
label.Text = check[0];
the label displays a 1.
I do not understand this please help.
First – you should be able to just use
File.ReadAllLinesinstead of reading the text and splitting….You may need to trim the results. If there is extra whitespace on the lines, the condition may fail. Try using:
This will trim off any whitespace, which should cause your conditional to succeed.
You can also put a breakpoint in, and inspect the values in the debugger. This will help you better diagnose the issue.