Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VB

Treat a plain string as URL and fetch query string values

1.00/5 (1 vote)
22 Dec 2011CPOL 22.1K  
A simpler way to parse a URL address string in VB.NET as URL itself and fetch query string values
Consider the below code statement:

VB
Dim strURLAddress As String
strURLAddress = "http://www.google.co.in/search?sourceid=chrome&ie=UTF-8&q=CodeProject"

Let's say the job is to fetch the query string value for "ie" in the above URL Address.

The plain and simple way is to use indexes, substring and get dirty with the string functions.

Here's a much better alternative:

VB
HttpUtility.ParseQueryString(strURLAddress)("ie")


ParseQueryString is a method of HttpUtility class under System.Web namespace.

It simply parses a query string into a NameValueCollection using UTF8 encoding.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)