Wednesday, April 13, 2011

parsing URL ?a=b params with VB.NET from plain string

I am using a string to store key=value pairs, it has same format as QueryString

How can I easily parse it to array? or can I somehow use interal class QueryString("paramname") to access it?

From stackoverflow
  • String.Split() probably will work for you....

  • ' parse to pairs
                    Dim resultarray As Array = allresultdata.Split("&")
                    Dim result1 As String
                    Dim keyvals2 As Array
                    For Each result1 In resultarray
                        keyvals2 = result1.Split()
                        keyvals.Set(keyvals2(0), keyvals2(1))
                    Next
    
  • You could use the System.Web.HttpUtility.ParseQueryString, this will give you a NameValueCollection. You can then access your values easily

    Dim keynameValue As String = nameValueCollection.Get("Keyname")
    
  • or can I somehow use interal class QueryString("paramname") to access it?

    If you need to access querystring from another class other then page code behind, use this :

    HttpContext.Current.Request.QueryString("parameterName")
    

0 comments:

Post a Comment