Saw this requested awhile ago on Matthew Reynolds's blog here:
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
NameValueCollec tion object
public static NameValueCollec tion NameValueCollec tion(string qs)
{
NameValueCollec tion nvc = new NameValueCollec tion();
//strip string data before the question mark
qs = qs.IndexOf('?') >0?qs.Remove(0, qs.IndexOf('?') +1):qs;
Array sqarr = qs.Split("&".To CharArray());
for(int i=0;i<sqarr.Len gth;i++)
{
string [] pairs =
sqarr.GetValue( i).ToString().S plit("=".ToChar Array());
nvc.Add(pairs[0],pairs[1]);
}
return nvc;
}
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
NameValueCollec tion object
public static NameValueCollec tion NameValueCollec tion(string qs)
{
NameValueCollec tion nvc = new NameValueCollec tion();
//strip string data before the question mark
qs = qs.IndexOf('?') >0?qs.Remove(0, qs.IndexOf('?') +1):qs;
Array sqarr = qs.Split("&".To CharArray());
for(int i=0;i<sqarr.Len gth;i++)
{
string [] pairs =
sqarr.GetValue( i).ToString().S plit("=".ToChar Array());
nvc.Add(pairs[0],pairs[1]);
}
return nvc;
}