日期:2014-05-18 浏览次数:20795 次
string pattern = @"(?im)\[Q\]([^\]]+)\[/Q\]\s*\[O\]([^\]]+)\[/O\]\s*\[S\]([^\]]+)\[/S\]"; string tempStr = File.ReadAllText(@"C:\Users\dell\Desktop\Test.txt",Encoding.GetEncoding("gb2312"));//读取文档 foreach (Match m in Regex.Matches(tempStr, pattern)) { //循环输出 三次 string value = m.Value;//[Q]1+2=?[/Q]\r\n[O]A.1 B.2 C.3[/O]\r\n[S]10[/S] string question = m.Groups[1].Value;//1+2=? string option = m.Groups[2].Value;//A.1 B.2 C.3 string s = m.Groups[3].Value;//10 }