How can I take the string foo[]=1&foo[]=5&foo[]=2 and return a collection with the values 1,5,2 in that order. I am looking for an answer using
foo[]=1&foo[]=5&foo[]=2
1,5,2
Here's an alternative solution using the built-in string.Split function:
string x = "foo[]=1&foo[]=5&foo[]=2"; string[] separator = new string[2] { "foo[]=", "&" }; string[] vals = x.Split(separator, StringSplitOptions.RemoveEmptyEntries);