Read line by line

Hello I have a TextBox full of lines of text and now all I want to do  is just read them Line by Line !


Regards


Answer this question

Read line by line

  • nimrodel

    Doesn't look like TextBox supports that, but I know another way using the String.Split function.


    public void SomeFunc()
    {
       string sText = MyTextBox.Text;
       string delimStr = "\n";
       char []delimeters = delimStr.ToCharArray();

       string []AllLines = sText.Split(delimeters);

       //Now AllLines has all of the lines of text from the textbox. Each line per array cell.

    }


  • Neil Harper

    Look at the TextBox.Lines properties.  It returns an array on the strings which represent each line in the TextBox.
  • Jim Griesmer

    The TextBox class has a property called Lines that gives you an array of strings, one for each line.

    Here's a C# code snippet that throws each line to the string in a MessageBox:


    for (int i = 0; i<this.textBox1.Lines.Length; i++)
    MessageBox.Show(this.textBox1.Lines[i]);  



  • abinaysh

    Use the TextBox.Lines property.


    for (int i = 0; i<this.textBox1.Lines.Length; i++)
    MessageBox.Show(this.textBox1.Lines[i]);

  • Brad Carroll

    Here is some sample code that might help you with your issue:


    string[] strArray = MyTextControl.Text.Split(Environment.NewLine.ToCharArray());

    foreach(string s in strArray)
    {
         MessageBox.Show(s);
    }

  • Mulktide

    OK, I didn't look hard enough. There is a Lines property.

    string []AllLines = MyTextBox.Lines;

    That would do what I was trying to achieve in the last example, in less code. It will fill the array, one text line per array cell.

  • Read line by line