[英]C# Windows Forms Application Read Textbox Line by Line
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? 是否有内置函数,例如c ++和c中的getline()
函数?
Should I use a normal textbox or a richtextbox? 我应该使用普通文本框还是富文本框?
TextBoxBase.Lines property is what you're looking for. 您正在寻找TextBoxBase.Lines属性。
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: 结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.