locked
readline in textbox

    Question

  • I would like to use ReadLine in a textbox and not in a txtfile.
    The following code doesn't seem to do the trick...

    Code Block

    public void readHighScore()
            {
                if (!File.Exists(textBox1.Text))
                {
                    return;
                }

                TextReader tr = new StreamReader(textBox1.Text);
                String input;

                while ((input = tr.ReadLine()) != null)
                {
                    textBox2.Text = (input);

    }

                tr.Close();
            }

    private void button1_Click(object sender, EventArgs e) 

    {

    readHighScore();

    }

        



    My goal: I want to read the textbox1 line by line and copy the last line to textbox2.
    All seems to work; only the task isn't done...
    Friday, December 14, 2007 7:19 PM

Answers

  • Then this:

     

    Code Block

    foreach (string line in textBox1.Lines)

    {

    //do something with each line here

    }

     

     

    Friday, December 14, 2007 7:38 PM

All replies

  • Why not:

     

    textBox2.Text = textBox1.Lines[textBox1.Lines.Length-1];

     

    ?

    Friday, December 14, 2007 7:26 PM
  • That's not my goal...try edit the code I gived so it works. I don't want that, it would be a bit useless

    I want to read through a text and when the readline sees a ' : ' - sign, it should be storred in string1 for example and then continue...
    Friday, December 14, 2007 7:32 PM
  • Then this:

     

    Code Block

    foreach (string line in textBox1.Lines)

    {

    //do something with each line here

    }

     

     

    Friday, December 14, 2007 7:38 PM