下面是我一直在使用的。虽然它确实有效,但当我试图计算一个相当大的文件时,我的程序就会锁定,例如10,000或更多行。小文件立即运行。有没有更好的方法来计算文本文件中的行数?
有没有更好的或应该说更快的方式来计算文本文件中的行数?
这里就是我目前使用:
Dim selectedItems = (From i In ListBox1.SelectedItems).ToArray()
For Each selectedItem In selectedItems
ListBox2.Items.Add(selectedItem)
ListBox1.Items.Remove(selectedItem)
Dim FileQty = selectedItem.ToString
'reads the data file and returns the qty
Dim intLines As Integer = 0
'Dim sr As New IO.StreamReader(OpenFileDialog1.FileName)
Dim sr As New IO.StreamReader(TextBox1_Path.Text + "\" + FileQty)
Do While sr.Peek() >= 0
TextBox1.Text += sr.ReadLine() & ControlChars.CrLf
intLines += 1
Loop
ListBox6.Items.Add(intLines)
Next
非常好...我不得不为VB调整它,但它似乎像来自以前的日夜! – Muhnamana
哈哈,调整。答案已经在VB中,但他只是不小心添加了分号。对不起,我违法了,不得不指出。 – Suamere