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++;

                   }

                 

 

你可能感兴趣的:(Collection)