1

给定一个文件:

Timestamp: some text and a number 1
Timestamp: some text and a number 33
Timestamp: some text and a number 1
Timestamp: some text and a number 22
Something totally different, maybe a new pattern
Timestamp: some text and a number 4
Timestamp: some text and a number 2
Something totally different, maybe a new pattern
Something totally different, maybe a new pattern

我想获得第 1 到 4 行(TYPE1)和第 5 行(TYPE2)、第 6,7 行(TYPE1)和第 8,9 行(TYPE2)的分组。

这可以在一个正则表达式中完成,还是我应该为每种类型创建一个表达式,然后逐行检查前一行是否为同一类型?

最后,我需要返回一个带有 pair(int start_char, int end_char) 的分组列表

4

1 回答 1

1

你可以试试这个

string[] lines = System.IO.File.ReadAllLines("your taext file");

       var Groups =( 
                from w in lines 
                group w by w[0] into g 
                select new { FirstLetterLine = g.Key, Lins = g }); 
于 2013-04-01T13:09:56.030 回答