Gary,
If you know the text file is going to be really small then it's not much of
an issue, but rather than reading all the data into the string[] lines
variable, maybe open the file, then go through and read each line. This
method is arguably more efficient in time and on the resources.
Have you tried stepping through this code to see what the values are for the
variables?
Also, I'd put in checks around the array accessors to ensure that when you
go "items[1]...." that you actually have a valid non-null array with at
least two entries [0] and [1].
Finally, are you expecting the text to be case sensitive or not? your code
is case sensitive at the moment because StartsWith is case-sensitive...
Thanks.
Dan.
"CCLeasing" <gary@ccleasing.co.ukwrote in message
news:1162913083.570302.256540@h54g2000cwb.googlegr oups.com...
Quote:
>I have a text file which consists of lines of data. Each line has units
of data seperated by semicolons, like so.
>
AAAA ; some text relating to AAAA ; some more text relating to AAAA
BBBB ; some text relating to BBBB ; some more text relating to BBBB
>
I have a form which consists of a combo box control, and text box
control.
combo box contol is called = comCrime
text box control is called = txtProtocol
>
I am trying to compare the value in a combo box with the contents of a
text file. I am trying to find the line in the text file that starts
with the text in the combo box. Once this line is found I would like to
populate the textbox control on my form with the text that lies between
the first and second semicolons of the line. I have tried the following
code but it isn't working. Can someone suggest a change please.
>
private void comCrime_TabIndexChanged(object sender, EventArgs e)
{
string[] lines = File.ReadAllLines(@"c:\protocol.txt");
>
foreach (string s in lines)
{
string[] items = s.Split(':');
>
if s.StartsWith(comCrime.Value) Then txtProtocol.Text =
s[1].ToString;
>
}
}
>