1 ///2 /// 获得字符串中开始和结束字符串中间得值 3 /// 4 /// 字符串 5 /// 开始 6 /// 结束 7 ///8 public static string GetMidValue(string str, string s, string e) 9 {10 Regex rg = new Regex("(?<=(" + s + "))[.\\s\\S]*?(?=(" + e + "))", RegexOptions.Multiline | RegexOptions.Singleline);11 return s.Trim('\\') + rg.Match(str).Value + e.Trim('\\');12 }
1 Listlistdetail=new List (); 2 string strhtml = "testaaa{aaa}testbbb{bbb}testccc{ccc}"; 3 for (int i = 0; i < 30; i++) 4 { 5 string find = GetMidValue(strhtml, "{ ", "}"); 6 if (find != "{}") 7 { 8 listdetail.Add(find); 9 if (i == 0)10 {11 strhtml = strhtml.Replace(find, " ");12 }13 else14 {15 strhtml = strhtml.Replace(find, " ");16 }17 }18 else19 {20 break;21 }22 }23 string end = strhtml;