使用 VB.NET 读取行数
如何计算我们上传的文件中的行数。该文件可以是文本文件,也可以是 CSV 或 Excel 文件。
我使用以下代码来获取记录计数,如下所示:
Dim FileCount = From lin1 As String In File.ReadAllLines(hidFilePath.Value.ToString())
Let dd = lin1.Count
Select dd
Dim file_count As Integer = FileCount.Count
但在某些情况下计数是错误的。
How to calculate the number of rows in a file which we have uploaded. The file might be either a text file or a CSV or Excel file.
I'm using the folowing code to get the record count like this:
Dim FileCount = From lin1 As String In File.ReadAllLines(hidFilePath.Value.ToString())
Let dd = lin1.Count
Select dd
Dim file_count As Integer = FileCount.Count
but in some cases the count is wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ReadAllLines
返回一个字符串数组,因此您可以简单地获取数组的长度。ReadAllLines
returns a string array, so you can simply take the length of the array.编辑:快速阅读问题并用循环解决方案回答
您可以将行数设置为整数并让读者读到文件末尾。
您可以使用计数变量并循环遍历文件,直到没有任何内容为止
EDIT: read question to fast and answered with a loop solution
You can set your linecount as an integer and have the reader read to the end of the file.
You can use a count variable and loop through the file until theres nothing