Is it possible to split a string by '&' and init a dictionary in one go or you have to use a string array first?
I want to take the url part:
?a=2&b=3
and load a dictionary<string,string>
Is it possible to split a string by '&' and init a dictionary in one go or you have to use a string array first?
I want to take the url part:
?a=2&b=3
and load a dictionary<string,string>
Duplicate of your own question...
As womp said, HttpUtility.ParseQueryString() is your best bet.
Edit:
After doing a little digging I found the following extension method NameValueCollectionExtensions.CopyTo(this NameValueCollection, IDictionary< string, object >) that you could use to populate a true IDictionary.
Based on the format given, I think you want something like this:
var dict = queryString
.Substring(1) // to skip the "?"
.Split("&")
.Select(s => s.Split("="))
.ToDictionary(sa => sa[0], sa => sa[1]);