我有一个简单的程序,它读取日志文本文件并尝试解析它。C#如何通过分组解析文本文件?
该程序将ablle“分组”/解析日志文本文件的“----------------------”我试图使用“.split”方法,但它不起作用。
基本上如果可能我希望程序将文本文件从每个“----------------”到“----------” -----“用于其他进程。
有人可以请指教的代码?谢谢!
我的代码:
class Program
{
static void Main(string[] args)
{
System.Collections.Generic.IEnumerable<String> lines = File.ReadLines("C:\\Syscrawl\\new.txt");
foreach (String r in lines.Skip(7))
{
String[] token = r.Split('-');
foreach (String t in token)
{
Console.WriteLine(t);
}
}
}
}
一个样值PF的文本文件;
Restore Point Info
Description : Installed Apache HTTP Server 2.2.16
Type : Application Install
Creation Time : Thu Dec 9 08:04:46 2010
C:\syscrawl\Restore\RP10\snapshot\_REGISTRY_USER_NTUSER_S-
1-5-21-1390067357-413027322-1801674531-500
Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs not found.
----------------------------------------
Restore Point Info
Description : Testing 0
Type : System CheckPoint
Creation Time : Thu Dec 9 08:05:43 2010
C:\syscrawl\Restore\RP11\snapshot\_REGISTRY_USER_NTUSER_S-
1-5-21-1390067357-413027322-1801674531-500
Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs not found.
----------------------------------------
Restore Point Info
Description : Installed Python 2.4.1
Type : Application Install
Creation Time : Thu Dec 9 08:09:12 2010
C:\syscrawl\Restore\RP12\snapshot\_REGISTRY_USER_NTUSER_S-
1-5-21-1390067357-413027322-1801674531-500
Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs not found.
----------------------------------------
Restore Point Info
Description : Installed AccessData FTK Imager.
Type : Application Install
Creation Time : Thu Dec 9 08:14:02 2010
C:\syscrawl\Restore\RP13\snapshot\_REGISTRY_USER_NTUSER_S-
1-5-21-1390067357-413027322-1801674531-500
Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs not found.
生成了很多错误。 “Split”方法不能将String作为变量来分割,而只能分割数组。 – JavaNoob 2010-12-11 16:26:17