算不了空白行? [英] Count no of blank line ?
本文介绍了算不了空白行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何计算文本文件中的空白行?
提前感谢。
How to count no of blank line in a text file?
Thanku in advance.
推荐答案
试试这个
Try this one
var inptuFileName = "C:\test.txt"";
var lines = File.ReadAllLines(inptuFileName).Where(arg = > string.IsNullOrWhiteSpace(arg));
int count = lines.Count();
确实没有一个好方法!:笑:
这个:计算字符串中的行数 [ ^ ]显示了许多计算行数的方法,您不难修改任何计算行数的方法。
但是有没有简单的解决方案:文本文件中并不存在行,它们只是处理它们的软件的约定,并使用行分隔符来区分它们!
There really isn't a nice way! :laugh:
This: Counting Lines in a String[^] shows a number of ways to count lines, and it wouldn't be difficult for you to modify any of those to count blank lines.
But there is no simple solution: "lines" don't really exist in text files, they are just a convention of the software which processes them and uses the "line separator character" to distinguish between them!
这篇关于算不了空白行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文