We Recommend

Beginning VB.NET Beginning VB.NET
Visual Basic .NET is the latest version of the most widely used programming language in the world, popular with professional developers and complete beginners alike. This book will teach you Visual Basic .NET from first principles. You'll quickly and easily learn how to write Visual Basic .NET code and create attractive windows and forms for the users of your applications.


Posted By

DaveChild on 09/11/08


Tagged

querystring


Versions (?)


VB.NET Add and Remove Querystring Variables


Published in: VB.NET 


  1. Public Function AddQuerystringVar(ByVal strURL As String, ByVal QuerystringKey As String, ByVal QuerystringValue As String) As String
  2. strURL = RemoveQuerystringVar(strURL, QuerystringKey) ' Remove value if already in URL
  3. If InStr(strURL, "?") = 0 Then
  4. Return strURL + "?" + QuerystringKey + "=" + QuerystringValue
  5. Else
  6. Return strURL + "&" + QuerystringKey + "=" + QuerystringValue
  7. End If
  8. End Function
  9.  
  10. Public Function RemoveQuerystringVar(ByVal strURL As String, ByVal QuerystringKey As String) As String
  11. Dim re As New Regex("(.*)(\?|&)" + QuerystringKey + "=[^&]+?(&)(.*)", RegexOptions.IgnoreCase)
  12. strURL = re.Replace(strURL + "&", "$1$2$4")
  13. strURL = Mid(strURL, 1, (strURL.Length - 1))
  14. Return strURL
  15. End Function

Report this snippet 

You need to login to post a comment.