MatchCollection 切割字符串

MatchCollection mc = Regex.Matches("id=5||name=text||item=0||selected=true", @"\w+=(?<value>[^\||]*)");
                   foreach (Match m in mc)
                   {
                       GroupCollection gc = m.Groups;
                       switch (i)
                       {
                           case 0:
                             id=  gc["value"].Value;
                               break;
                           case 1:
                              name= gc["value"].Value;
                               break;
                           case 2:
                            item=  gc["value"].Value;
                               break;
                           case 3:
                             selected=  gc["value"].Value;
                               break;
                           default:
                               break;
                       }

                       i++;
                   }
                 

 

posted @ 2012-04-19 14:24  小川丶  阅读(260)  评论(0)    收藏  举报