If I have a URL but as a string e.g. www.example.com?q=1234&h=4567
how can I pick out e.g. "q"
I'm picking the url up from a database so I can't use request.querystring("q")
If I have a URL but as a string e.g. www.example.com?q=1234&h=4567
how can I pick out e.g. "q"
I'm picking the url up from a database so I can't use request.querystring("q")
You can use HttpUtility.ParseQueryString:
string url = new Uri("http://www.example.com?q=1234&h=4567").Query;
System.Collections.Specialized.NameValueCollection nvc = System.Web.HttpUtility.ParseQueryString(url);
foreach (string key in nvc.AllKeys)
{
// ...
}
(note that i've added the "http" to the url, otherwise you could not create an Uri
)