?
Solved

Removing a QueryString

Posted on 2006-05-27
7
Medium Priority
?
263 Views
Last Modified: 2008-03-10
Is there a method I can use to remove part of a QueryString. For example I the url

bob.asp?id=12345&url=next.asp&new=jimmy

If I want to remove url but keep new and id, how would I do that?

Thanks!
0
Comment
Question by:eadam-uk
5 Comments
 
LVL 97

Expert Comment

by:Lee W, MVP
ID: 16777237
Not sure what you're looking for without a more clear code example...


You could just do this:

Original URL
url="bob.asp?id=12345&url=next.asp&new=jimmy"

new URL
url="bob.asp?id=" & Request.QueryString("id") & "&new=" & Request.QueryString("new")
0
 
LVL 4

Expert Comment

by:HarperBen
ID: 16778931
If your looking to extract the "new" and "Id" values then
New = Request.QueryString("New")
Id = Request.QueryString("Id")

If you are looking to keep the string intact and just get rid of the bob.asp
then text functions.

URL = "bob.asp?id=12345&url=next.asp&new=jimmy"
NewUrl = Mid(URL,instr(1,URL,"?",1),Len(URL)-instr(1,URL,"?",1)+1)

This will variable NewUrl the value"?id=12345&url=next.asp&new=jimmy"
0
 
LVL 1

Expert Comment

by:Magnussen
ID: 16786148
You may want to redirect to 'bob.asp?id=12345&new=jimmy' by the help of this code:

Response.Redirect("bob.asp?id=12345&new=jimmy")
0
 
LVL 1

Accepted Solution

by:
mihovski earned 2000 total points
ID: 16813893
Here i worte a function to do what you want:

Function RemoveQueryString(ByVal OriginalQS, ByVal RemoveItem)
      If OriginalQS = "" Then Exit Function
      If RemoveItem = "" Then Exit Function
      Dim newQS: newQS = ""
      tmpQS = Split(OriginalQS ,"&")
      For i=0 To UBound(tmpQS)
            tmpPair = Split(tmpQS(i),"=")
            If Trim(tmpPair(0)) <> Trim(RemoveItem) Then
                  If Trim(newQS) <> "" Then newQS = newQS &"&"
                  newQS = newQS & tmpPair(0) &"="& tmpPair(1)
            End If
      Next
      RemoveQueryString = newQS
End Function

Just pass to the function the full query string and the value you want to remove and it will return you the querystring without the part you want to remove, example:

OriginalQueryString = "id=12345&url=next.asp&new=jimmy"
newQueryString = RemoveQueryString(OriginalQueryString,"url")
response.write newQueryString

it will return id=12345&new=jimmy

Tip: To get the querystring in a page use: Request.ServerVariables ("QUERY_STRING")
and it will return the querystring without the filename and ? (filename.asp?)

cheers,
Vladimir

0
 

Author Comment

by:eadam-uk
ID: 17162819
Thanks Valdimir, just what I wanted. Apologies for the tardy response back but looks like the admin got it right!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question