matthew king

matthew king

  • NA
  • 52
  • 0

array help?

Sep 15 2009 9:02 AM

 
Sir/Ma'am

 

Have a question regarding arrays.  I will do my best to explain what I'm trying to do.  Let's stay you have a text file (test.txt) with the following format:

 

,

 ---                          1                              2                              3                              4                              5                              6

,

100                    101                              102                         103                         104                         105                         106

 

200                    201                              202                         203                         204                         205                         206

 

300                    301                              302                         303                         304                         305                         306

 

 

Now you have a form with three textboxes and a button; the intent is for the user to enter numbers into textboxes 1 and 2 and pushes the button.  For this example we will say the user inputs 300 into Textbox1 and 3 into textbox2.  Upon pushing the button I  would like  textbox3 to return a value of 303.  Example 2.   The user enter 100 into Textbox1 and 6 into texbox2, clicks a button and textbox3 is populated with 106.  I hope this makes sense to those of you kind enough to assist.  Is something like this possible with C# using streamreader?  I was able to come up with the following code, but it only reads a single line and isn't very dynamic.  Obviously what I'm trying to do far exceeds my skill and would appreciate some assistance. 

// Read the file and display it line by line.

 

System.IO.

 

StreamReader file = new System.IO.StreamReader(@"C:\test.txt");

 

while ((line = file.ReadLine()) != null)

 

{

 

Console.WriteLine(line); string[] lineStrings = line.Split(new char[] { ' ' },

 

StringSplitOptions.RemoveEmptyEntries); if (lineStrings.Length > 0)

 

{

 

if (lineStrings[0] == textBox1.Text)

 

{

 

textBox3.Text = lineStrings[1];

 

if (lineStrings[0] == textBox1.Text)

 

{

 

textBox3.Text = lineStrings[1];

 

Console.ReadLine();


Answers (6)