C# 我可以根据线型将文本文件与正则表达式分组吗
给定一个文件:C# 我可以根据线型将文本文件与正则表达式分组吗,c#,regex,C#,Regex,给定一个文件: 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:
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行(类型1)和第5行(类型2)、第6,7行(类型1)和第8,9行(类型2)的分组
这可以在一个正则表达式中完成,还是应该为每种类型创建一个表达式,然后逐行检查前一行是否为同一类型
最后,我需要返回一个带有pair的分组列表(int start\u char,int end\u char)您可以试试这个
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 });
你可以试试这个
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 });
是否要对组中的所有或仅连续项进行分组?(即,您是在寻找4个组,还是仅在这里寻找2个组?)。我想把文本分成相似的组。其中相似性基于当前行和前一行的正则表达式模式是否匹配。是否要对组中的所有或仅连续项进行分组?(即,您是在寻找4个组,还是仅在这里寻找2个组?)。我想把文本分成相似的组。其中相似性基于正则表达式模式是否与当前行和前一行匹配。我可能会使用类似的方法,可以为group by创建一个将行拆分为一个组的方法。我可能会使用类似的方法,可以为group by创建一个将行拆分为一个组的方法。