0

I needed to get values out of a string in a QueryString format, that is such as: data1=value1&data2=value2...

Someone suggested I used HttpUtility.ParseQueryString to get the value, I've searched and searched but I can't find any documentation or implementation of this and the Microsoft documentation for it doesn't explain how it works, can someone tell me hwat I'm doing wrong, my code is below;

Public Shared Sub ProcessString(ByVal Vstring As String)
    Dim var As NameValueCollection = HttpUtility.ParseQueryString(Vstring)
    Dim vname As String = var.QueryString("VNAME")
End Sub

2 Answers 2

1

MSDN has an example.

' Parse the query string variables into a NameValueCollection.
Dim qscoll As System.Collections.Specialized.NameValueCollection = HttpUtility.ParseQueryString(Vstring)
Dim vname As String = qscoll("VNAME")

A NameValueCollection represents a collection of associated String keys and String values that can be accessed either with the key or with the index.

Sign up to request clarification or add additional context in comments.

2 Comments

problem is NameValueCollection keeps coming up as not a valid data type do you know how I can fix this?
@user1044220: Edited my answer to provide the full path to the class. You need to add Imports System.Collections.Specialized or use the fully qualified name as in my answer.
0

I found the problem, I was referencing everything fine but I was doing it in a separate .VB dependency file, once I did it on the actual code behind of the aspx form that solved the problem and it all worked. So now I'm just passing the string from Codebehind as a specialised.NameValue collection in to the function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.