我想看框2的行數,為什麼一開始就是2
明明最後只有5行,但是顯示6 。。。
代碼如下:
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog fileName = new OpenFileDialog();
fileName.InitialDirectory = "D:\Users\zwj\Desktop\調試工具";
fileName.Filter = "All files (*.*)|*.*|* files (*.*)|*.*";
fileName.FilterIndex = 2;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
richTextBox1.LoadFile(openFileDialog1.FileName,
RichTextBoxStreamType.PlainText);
}
}
private void button1_Click(object sender, EventArgs e)
{
string str = richTextBox1.Text;
string[] lines = str.Split(Environment.NewLine.ToCharArray());
for (int i = 1; i < lines.Length; i++)
{
Console.WriteLine(lines[i]);
string[] linecell = lines[i].Split(new char[] { ',' });
if (linecell.Length > 2)
{
richTextBox2.Text = richTextBox2.Text + linecell[2]+ "\r\n";//讀取出身份證號碼
}
MessageBox.Show(richTextBox2.Lines.Count().ToString());
}
}
是因為多了回車換行符嗎?該怎麼去掉他
你的代碼自動增加了\r\n在後面,肯定會形成新行了,蓋下面的
if (linecell.Length > 2)
{
richTextBox2.Text = richTextBox2.Text +( richTextBox2.Text==""?"": "\r\n")+ linecell[2];//讀取出身份證號碼
}