Reputation: 149
I want to make a program that has a multiline textbox, and the program will read it line by line.
All I need is to get the line into a string, and after I'm finished with that line, it moves on.
How can I do that?
Is there a built in function, like there is the getline()
function in c++ and c?
Should I use a normal textbox or a richtextbox?
Upvotes: 0
Views: 3017
Reputation: 10152
TextBoxBase.Lines property is what you're looking for.
Per request, here's a sample:
Code:
namespace SomeApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// For each line in the rich text box...
for (int i = 0; i < richTextBox.Lines.Length; i++)
{
// Show a message box with its contents.
MessageBox.Show(richTextBox.Lines[i]);
}
}
}
}
Result:
Upvotes: 3