tags:

views:

224

answers:

2

.NET has the Uri class.

Perl has its URI module.

The major difference is that URI.pm allows you to retrieve the query string components as a hash, and set a hash into the URI to construct a nice URI with query arguments. I don't see anything like that on the .NET side. Is there some hidden class I don't know about?

+2  A: 

Another utility provides for parsing query strings: System.Web.HttpUtility.ParseQueryString() - Parses a query string into a NameValueCollection.

An example from HttpUtility doc:

String querystring;
...
// Parse the query string variables into a NameValueCollection.
NameValueCollection qscoll = HttpUtility.ParseQueryString(querystring);

// Iterate through the collection.
StringBuilder sb = new StringBuilder();
foreach (String s in qscoll.AllKeys)
{
    sb.Append(s + " - " + qscoll[s] + "<br />");
}
gimel
Right, I can use this other string to parse a query string, but how do I put it back? Starting with a collection, there doesn't appear to be a facility for getting a query string.
BRH
Sorry, seems like you have to iterate through the collection to generate a query string :-(
gimel
A: 

The answer, apparently is "No". There is no built-in class in the .NET framework that can take a collection of names and values and produce a query string or allow you to directly modify the query string component of a URI as if it were a collection.

BRH