Click here to Skip to main content
15,893,668 members
Articles / Programming Languages / Visual Basic
Tip/Trick

Treat a plain string as URL and fetch query string values

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
22 Dec 2011CPOL 21.6K   2   5
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)



Comments and Discussions

 
GeneralMy vote of 1 Pin
PetePuma3-Oct-12 15:22
PetePuma3-Oct-12 15:22 
NewsRe: My vote of 1 Pin
Jyothikarthik_N6-Oct-12 12:30
Jyothikarthik_N6-Oct-12 12:30 
PetePuma, The whole idea was to show such an option/alternate way exists. Folks who've never thought of such way might find this new.

Thanks for the feedback though! Smile | :)
JK

GeneralJyothikarthik_N,thank you for your helping.I am coding proje... Pin
tdyso_zmh27-Dec-11 23:18
tdyso_zmh27-Dec-11 23:18 
GeneralI tried it but failed.There is no "HttpUtility" in "System.... Pin
tdyso_zmh22-Dec-11 21:46
tdyso_zmh22-Dec-11 21:46 
GeneralRe: tdyso, Try explicitly "Add Reference" to System.Web Namespa... Pin
Jyothikarthik_N22-Dec-11 22:15
Jyothikarthik_N22-Dec-11 22:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.