将文本文件行添加到ListBox [英] Add lines of text file to ListBox
本文介绍了将文本文件行添加到ListBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何查找某个文本文件中的行数?
例如
如果文本文件如下所示:
__________
例子
文件
__________
然后,我希望它返回2.
How would I go about finding how many lines are in a certain text file?
E.g.
If Text file looked like this:
__________
Example
File
__________
Then I would want it to return 2.
推荐答案
您可以使用File.ReadAllLines("file path").Length
.这将为您提供文件中的行数.
You can us File.ReadAllLines("file path").Length
. This will give you the number of lines in the file.
将文件加载到字符串中并按如下方式拆分-
string [] array = file.Split(new char [] {''\ n''});
数组的计数将为您提供字符串数.
Load the file into a string and split as follows -
string[] array = file.Split(new char[]{''\n''} );
The count of array would give you the number of strings.
这篇关于将文本文件行添加到ListBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文