65.9K
CodeProject is changing. Read more.
Home

Treat a plain string as URL and fetch query string values

starIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

1.00/5 (1 vote)

Dec 22, 2011

CPOL
viewsIcon

22122

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:
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:
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.