Saw this requested awhile ago on Matthew Reynolds's blog here:
http://www.dotnet247.com/247referenc.../11/57944.aspx
Problem: often times I deal with querystring-formatted strings w/o the
actual HttpRequest object involved.
Solution: the function accepts such a querystring-type string and outputs a
NameValueCollection object
public static NameValueCollection NameValueCollection(string qs)
{
NameValueCollection nvc = new NameValueCollection();
//strip string data before the question mark
qs = qs.IndexOf('?')>0?qs.Remove(0,qs.IndexOf('?')+1):q s;
Array sqarr = qs.Split("&".ToCharArray());
for(int i=0;i<sqarr.Length;i++)
{
string [] pairs =
sqarr.GetValue(i).ToString().Split("=".ToCharArray ());
nvc.Add(pairs[0],pairs[1]);
}
return nvc;
}