使用 vb.net 读取行数 [英] Reading line count using vb.net

查看:41
本文介绍了使用 vb.net 读取行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算编号.我们上传的文件中的行数,可能是文本文件、csv 或 excel 文件.我使用代码来获取这样的记录数:

How to calculate the no. of rows in the file which we have uploaded that might be either a text file or csv or excel file. Im using the code to get the records 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 im getting wrong count. it is not showing the exact count.

请帮忙,我应该能够在不循环文件中的每条记录的情况下获得计数.

Please help and i should be able to get the count without looping each record in the file.

谢谢.

推荐答案

ReadAllLines 返回一个字符串数组,所以你可以简单地取数组的长度.

ReadAllLines returns a string array, so you can simply take the length of the array.

Dim file_count As Integer = _
    File.ReadAllLines(hidFilePath.Value.ToString()).Length

这篇关于使用 vb.net 读取行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆