在C#中读取行的具体数目从文本文件 [英] Reading specific number of lines from text file in c#
本文介绍了在C#中读取行的具体数目从文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用下面的StreamReader从文本文件阅读
I'm using the following StreamReader to read from text file
string temp = fs.ReadToEnd ();
readlines[i] = temp;
我想读取文本文件(让我们说行的具体数量,从行号直到1号线仅300),然后写行到数组的一个元素。谁能帮助吗?提前致谢。
I want to read a specific number of lines from the text file (let we say, from line number 1 until line number 300 only), then write the lines into one element of array. Could anyone help please? thanks in advance.
推荐答案
试图用一个简单的文本文件。
Tried with a simple text file.
var lines = File.ReadLines("yourfile").Take(300);
readlines[i] = string.Join("-", lines);
这篇关于在C#中读取行的具体数目从文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文