我有一个程序,它读取文本文件并将其处理为分成的部分。
所以问题是如何更改程序,以允许程序在使用Stream Reader读取文件时跳过文件的前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("============================================================");
}
}
}
Split()
方法为什么不起作用?当然,在处理大文件时它的效率非常低下,但它是可用的。 - Ilia G