Most optimal way to parse QueryString within a string in C#

The following will return: 5076639 which is the value of the ipage param

using System.Collections.Specialized;

        // URL to parse
        string xmlHTMLUrl = "";

        // Ignore the host/path.  Just get the params in the URL

        // Create a URI object from the URL string.  
        Uri uriXML = new Uri(xmlHTMLUrl);

        // Extract just the QueryString portion of the URL
        string xmlHTMLUrlParms = uriXML.Query;
        NameValueCollection nameValueTable = new NameValueCollection();
        nameValueTable = HttpUtility.ParseQueryString(xmlHTMLUrlParms);

        // Return the ipage parameter value
        string iPageID = nameValueTable["ipage"];


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s