我有一个文本文件,内容如下:
+++++ jcguox 4/2/2011 6:19:47 AM
text here
+++++ viveksix 8/24/2012 4:09:17 AM
text again
+++++ viveksix 8/25/2012 11:01:30 AM
----- Vivek Singh 08/25/2012 11:28:12 PM
adding text
+++++ viveksix 8/25/2012 11:02:52 AM
adding more
我想选择所有类型的模式,+++++name date time
但arraylist
条件是:
- 如果
-----name date time appears
紧随其后,+++++name date time
则不+++++name date time
应将其添加到arraylist
. - 只有当文本出现之后
+++++name date time
才+++++name date time
应该添加到arraylist
.
现在我能够解析两种模式+++++name date time
并-----name date time
使用Regex.matches
.
问题是如何在循环中应用,例如:
foreach(Match m in Regex.Matches(textfile,@"+++++name date time" + @"-----name date time")
{
if(after +++++name date time text is there)
arraylist.Add("+++++name date time");
else if(after +++++name date time -----name date time is there)
//do not add in arraylist;
}
output for above case is :
+++++ jcguox 4/2/2011 6:19:47 AM
+++++ viveksix 8/24/2012 4:09:17 AM
+++++ viveksix 8/25/2012 11:02:52 AM