streamreader (matching lines)
Sir/ma'am
I have a problem which is giving me fits.
I have a form that will return an arbitrary value of 1 to 1000 in textbox2. Once that value is returned, the user clicks a button to initiate a quarry of a file named test.txt(data below). The quarry will look for a line matching the value returned in textbox2. This program works like a charm if the value returned in textbox2 matches that of test.txt (e.g. if textbox2 equals 420 the following will result: textbox3.Text = rm125, textbox3.Text = rm131, and textbox3.Text =rm141)
However, if the value returned in textbox2 equals 421 then nothing will be returned in textbox 3 thru 5, obviously. I'm trying to determine a method for overcoming this obstacle. In theory, if 421 thru 424 were returned to textbox2, I would like it to return the same value as 420 (e.g. if textbox2 equals 421 thru 424 the following will result: textbox3.Text = rm125, extbox3.Text = rm131, and textbox3.Text =rm141). Is there a way to accomplish this task, without entering 1000 entries in test.txt?
I welcome any criticism or suggestions!
using (StreamReader readines = new StreamReader(@"C:\Program Files\test.txt"))
{
string line;
while ((line = readines.ReadLine()) != null)
{
Console.WriteLine(line); string[] lineStrings2 = line.Split(new char[] { ',' },
StringSplitOptions.RemoveEmptyEntries); if (lineStrings2.Length > 1)
if (lineStrings2[0] == textbox2.Text)
{
textbox3.Text = lineStrings2[1];
textbox4.Text = lineStrings2[2];
textbox5.Text = lineStrings2[3];
// C:\Program Files\test.txt
;
[DATA]
;
16, rm12,rm13,rm14
21, rm11,rm133,rm141
415, rm124,rm130,rm140
420, rm125,rm131,rm141
425, rm126,rm132,rm142