多行文本框的问题 请问如何把多行文本框中的某一行的内容读出来。谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void button1_Click(object sender, EventArgs e) { string[] items = textBox1.Text.Split('\n'); foreach (string s in items) { MessageBox.Show(s); } }注意:空行也算 用\n的话必须是用回车换行,如果需要非回车换行的某一行的话用这个方法。 private void button1_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); int lineCode = 2;//第三行 string text = textBox1.Text; for (int i = 0; i < text.Length; i++) { if (textBox1.GetLineFromCharIndex(i) > lineCode) { break; } if (textBox1.GetLineFromCharIndex(i) == lineCode) { sb.Append(text[i].ToString()); } } MessageBox.Show(sb.ToString()); } int lineCode = 2;//第三行 int startCharIndex = textBox1.GetFirstCharIndexFromLine(lineCode); string text = textBox1.Text; int endCharIndex = text.Length; int tempIndex = textBox1.GetFirstCharIndexFromLine(lineCode + 1); if (tempIndex != -1) { endCharIndex = tempIndex; } MessageBox.Show(text.Substring(startCharIndex, endCharIndex - startCharIndex));修改了一下,不需要循环。 private void button3_Click(object sender, EventArgs e) { foreach (String str1 in textBox1.Lines) { listBox1.Items.Add(str1);//str1为某行的内容 } } 求正则表达式 DataTable 导出Exexl 或者 dataGridView导出Excel 结果怎么会是10? 该类别的图书,只可借出2本?怎么判断? 关于使用UltraEdit作为C#源代码编辑器,而不使用Visual Studio c# 如何过设定时间间隔后再触发一个函数? **********征集讨论 ORM 中的集合运算******** 来者有分 新手,问一个简单的问题 如何读取Response的内容 去掉BT1,当LB4=PASS时候自动保存数据! [高分,简单,却没有人肯指教...]不同子窗体间的数据同步. 配置文件 数据库的相对路径
{
string[] items = textBox1.Text.Split('\n');
foreach (string s in items)
{
MessageBox.Show(s);
}
}注意:空行也算
{
StringBuilder sb = new StringBuilder();
int lineCode = 2;//第三行
string text = textBox1.Text;
for (int i = 0; i < text.Length; i++)
{
if (textBox1.GetLineFromCharIndex(i) > lineCode)
{
break;
} if (textBox1.GetLineFromCharIndex(i) == lineCode)
{
sb.Append(text[i].ToString());
}
} MessageBox.Show(sb.ToString());
}
int lineCode = 2;//第三行
int startCharIndex = textBox1.GetFirstCharIndexFromLine(lineCode);
string text = textBox1.Text;
int endCharIndex = text.Length;
int tempIndex = textBox1.GetFirstCharIndexFromLine(lineCode + 1);
if (tempIndex != -1)
{
endCharIndex = tempIndex;
} MessageBox.Show(text.Substring(startCharIndex, endCharIndex - startCharIndex));
修改了一下,不需要循环。
{
foreach (String str1 in textBox1.Lines)
{
listBox1.Items.Add(str1);//str1为某行的内容
}
}