下面是我一直在使用的。雖然它確實有效,但當我試圖計算一個相當大的文件時,我的程序就會鎖定,例如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