计算文本文件中行的最快方法是什么? [英] What is the fastest way to count lines in a text file?

查看:61
本文介绍了计算文本文件中行的最快方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想非常快速地计算文本文件中的行数,而不必使用

来读取每一行并增加一个计数器。我在VB.NET和C#工作。

有没有人有一个如何做到这一点的非常快的例子?


谢谢,


Matt

I want to very quickly count the number of lines in text files without having
to read each line and increment a counter. I am working in VB.NET and C#.
Does anyone have a very fast example on how to do this?

Thanks,

Matt

推荐答案

Mesterak,


在这些新闻组的不同测试中显示只使用字符串作为Char数组循环通过

文件(不测试字符串然后在char上测试
)并且在linebreack char上进行测试主要是最快的

方法。


我希望这会有所帮助,


Cor
Mesterak,

In different test in these newsgroups have showed that just looping through
the file using the string as a Char array (not testing on a string however
testing on a char) and testing on the linebreack char is mostly the fastest
method.

I hope this helps,

Cor


你能否提供一个代码示例,或者将我指向相关的帖子?


" Cor Ligthert [MVP]"写道:
Can you provide a code example else point me to the relevant posts?

"Cor Ligthert [MVP]" wrote:
Mesterak,

在这些新闻组中的不同测试表明,只需使用字符串作为Char数组循环浏览文件(没有在字符串上测试但是在char上测试并且在linebreack char上测试大多是最快的方法。

我希望这有帮助,

Mesterak,

In different test in these newsgroups have showed that just looping through
the file using the string as a Char array (not testing on a string however
testing on a char) and testing on the linebreack char is mostly the fastest
method.

I hope this helps,

Cor



也许使用正则表达式可以快速解决(对于大文本

文件)。

你将计算\\\或n的匹配数\\


-

Vadym Stetsyak又名Vadmyst
http://vadmyst.blogspot.com


mesterak <我****** @ discussions.microsoft.com>在消息中写道

新闻:C9 ********************************** @ microsof t.com ...
Maybe using regular expression can be fast solution ( for large text
files ).
You will count matches for \r\n or \n

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

"mesterak" <me******@discussions.microsoft.com> wrote in message
news:C9**********************************@microsof t.com...
我想非常快速地计算文本文件中的行数而不用
来读取每一行并递增一个计数器。我在VB.NET和C#工作。
有没有人有一个非常快的例子来说明如何做到这一点?

谢谢,

Matt
I want to very quickly count the number of lines in text files without
having
to read each line and increment a counter. I am working in VB.NET and C#.
Does anyone have a very fast example on how to do this?

Thanks,

Matt



这篇关于计算文本文件中行的最快方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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