我有一個程序,它讀取一個文本文件並將其處理爲分段。C#如何使用流讀取器讀取文本文件時跳過行數?
所以問題是如何更改程序以允許程序在使用流讀取器讀取文件時跳過讀取文件的前5行?
有人請告知代碼嗎?謝謝!
的代碼:
class Program
{
static void Main(string[] args)
{
TextReader tr = new StreamReader(@"C:\Test\new.txt");
String SplitBy = "----------------------------------------";
// Skip first 5 lines of the text file?
String fullLog = tr.ReadToEnd();
String[] sections = fullLog.Split(new string[] { SplitBy }, StringSplitOptions.None);
//String[] lines = sections.Skip(5).ToArray();
foreach (String r in sections)
{
Console.WriteLine(r);
Console.WriteLine("============================================================");
}
}
}
所以最新的問題與使用註釋掉行? – 2010-12-11 18:54:08
它向專家表明.split方法不起作用。 – JavaNoob 2010-12-11 19:00:38
[C#如何在文本轉換爲數組之後在文本文件中跳過行的可能的重複?](http://stackoverflow.com/questions/4417916/c-how-to-skip-lines-in-text-file-after -text-coverted-array) – ChrisF 2010-12-11 19:01:23