给定一个文件:
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)的分组。
这可以在一个regualar表达式中完成,还是应该为每种类型创建一个表达式,然后逐行检查,如果前一行是相同的类型?
最后我需要返回一个分组列表(int start_char,int end_char)
答案 0 :(得分: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 });