Removing a Querystring Name & Value

S

scott

Below, I'm trying to remove the querystring name& value of "catID=12".
I mananged to isolate the RESULTS part, but I need to be able to strip the
querystring name and it's value, no matter if the value is 1, 2 or 3 digits.
I chose to isolate the part I'd be removing below because I know I can take
it
and run a replace and get correct string, although I hardcoded the qs name.

Basically, I'd like to end up with a function that I could just pass the
name of the querystring and the function would remove the qs name and it's
value.

One other issue, if the querystring name and value are the only part of the
querystring, I need to delete the "?" within the qs.

Any help?

CODE:

sQueryString = "millID=2&catID=12"

iMarker = InStr(sQueryString ,"catID")
mystring= Right(sQueryString ,Len(sQueryString )-iMarker+1)


RESULTS:
mystring=catID=1
 
C

Chris Hohmann

scott said:
Below, I'm trying to remove the querystring name& value of "catID=12".
I mananged to isolate the RESULTS part, but I need to be able to strip the
querystring name and it's value, no matter if the value is 1, 2 or 3
digits.
I chose to isolate the part I'd be removing below because I know I can
take it
and run a replace and get correct string, although I hardcoded the qs
name.

Basically, I'd like to end up with a function that I could just pass the
name of the querystring and the function would remove the qs name and it's
value.

One other issue, if the querystring name and value are the only part of
the
querystring, I need to delete the "?" within the qs.

Any help?

<%
Function Remove_QS_Parameter(qs, p)
Dim retVal, re
Set re = New RegExp
re.Pattern = "(\?|&)" & p & "=.*?(&|$)"
retVal = re.Replace(qs,"$2")
If Left(retVal,1) = "&" Then retVal = "?" & Mid(retVal,2)
Remove_QS_Parameter = retVal
End Function

CONST qs = "?param1=1&param2=02&param3=003"
Response.Write Remove_QS_Parameter(qs,"param1") & "<br>"
Response.Write Remove_QS_Parameter(qs,"param2") & "<br>"
Response.Write Remove_QS_Parameter(qs,"param3") & "<br>"
%>
 
S

scott

here's results below: why the paragraph mark? also results are close, but
not right. can you correct, i can't fix your code.


qs: ?param1=1¶m2=02¶m3=003

results:
?param2=02¶m3=003
?param1=1¶m3=003
?param1=1¶m2=02
 
S

scott

my browser is showing paragraph marks where ampersand marks should be, and
formula is wrong.
 
C

Chris Hohmann

scott said:
here's results below: why the paragraph mark? also results are close, but
not right. can you correct, i can't fix your code.


qs: ?param1=1¶m2=02¶m3=003

results:
?param2=02¶m3=003
?param1=1¶m3=003
?param1=1¶m2=02

My code is fine. However, you may be cutting and pasting in a non-standard
way such that the paste operation is interpreting the occurrences of "&para"
as the paragraph entity character. Try the following:

1. Open Outlook Express and highlight the code I provided
2. Hit CTRL+C to copy the text into the copy/paste buffer
3. Open Notepad
4. Hit CTRL+V to paste the copied text into the Notepad window.
5. Hit CTRL+S to save the file. Save the file with a ".asp" extension and
place it somewhere in your web directory
6. Open Internet Explorer and navigate to the newly saved file.
7. Report back on whether or not this solves your problem.
 
S

scott

this is results after changing the qs name, your previous code rendered
paragraph marks. see the problem?

i'm a quadraplegic, i'm in a hospital, can you help me fix a function as
described before? it's really hard for me to type.

?myparam2=02&myparam3=003
?myparam1=1&myparam3=003
?myparam1=1&myparam2=02
 
C

Chris Hohmann

scott said:
this is results after changing the qs name, your previous code rendered
paragraph marks. see the problem?

i'm a quadraplegic, i'm in a hospital, can you help me fix a function as
described before? it's really hard for me to type.

?myparam2=02&myparam3=003
?myparam1=1&myparam3=003
?myparam1=1&myparam2=02

I'm sorry to here about your condition. I can empathize as I am also
disabled and have spent considerable time hospitalized. Would it be possible
for you to show my previous reply to a nurse, aide or a computer savvy
visitor? Cutting and pasting the code I provided should be a simple
procedure for anyone who has even a small bit of experience with computers.
I would also strongly recommend that you speak with an occupational
therapist about getting adaptive technologies to facilitate the use of
computers.
 
S

scott

i pasted ascii text chris. it's listed below. i'm a c5/c6 quad, just asking
for a little professional courtesy. if you can't fix your code, thanks
anyway.

i'll repost.



your code:


<%
Function Remove_QS_Parameter(qs, p)
Dim retVal, re
Set re = New RegExp
re.Pattern = "(\?|&)" & p & "=.*?(&|$)"
retVal = re.Replace(qs,"$2")
If Left(retVal,1) = "&" Then retVal = "?" & Mid(retVal,2)
Remove_QS_Parameter = retVal
End Function

CONST qs = "?myparam1=1&myparam2=02&myparam3=003"

Response.Write Remove_QS_Parameter(qs,"myparam1") & "<br>"
Response.Write Remove_QS_Parameter(qs,"myparam2") & "<br>"
Response.Write Remove_QS_Parameter(qs,"myparam3") & "<br>"
%>


YOUR RESULTS;


?myparam2=02&myparam3=003
?myparam1=1&myparam3=003
?myparam1=1&myparam2=02
 
C

Chris Hohmann

scott said:
i pasted ascii text chris. it's listed below. i'm a c5/c6 quad, just asking
for a little professional courtesy. if you can't fix your code, thanks
anyway.

i'll repost.



your code:


<%
Function Remove_QS_Parameter(qs, p)
Dim retVal, re
Set re = New RegExp
re.Pattern = "(\?|&)" & p & "=.*?(&|$)"
retVal = re.Replace(qs,"$2")
If Left(retVal,1) = "&" Then retVal = "?" & Mid(retVal,2)
Remove_QS_Parameter = retVal
End Function

CONST qs = "?myparam1=1&myparam2=02&myparam3=003"

Response.Write Remove_QS_Parameter(qs,"myparam1") & "<br>"
Response.Write Remove_QS_Parameter(qs,"myparam2") & "<br>"
Response.Write Remove_QS_Parameter(qs,"myparam3") & "<br>"
%>


YOUR RESULTS;


?myparam2=02&myparam3=003
?myparam1=1&myparam3=003
?myparam1=1&myparam2=02

Sigh. I'd be happy to "fix" my code. Just tell me what's wrong with it.
Otherwise, you probably are better off reposting, since I am obviously
missing something. Good luck.
 
S

scott

no, it is i who have missed something, i deeply apologize for temporary
stupidity. the medication is affecting my brain more than i thought.
 
C

Chris Hohmann

scott said:
no, it is i who have missed something, i deeply apologize for temporary
stupidity. the medication is affecting my brain more than i thought.

No problem. Please don't hesitate to post again if you have any other
questions. I look forward to helping if I am able.

Yours in respect and friendship,
Chris Hohmann
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top