我有一個簡單的程序,它讀取日誌文本文件並嘗試解析它。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