且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除查询字符串名称&值

更新时间:2023-02-14 19:58:10

"斯科特" < SC *** @ sbailey.com>在消息中写道

news:eC ************** @ tk2msftngp13.phx.gbl ...
"scott" <sc***@sbailey.com> wrote in message
news:eC**************@tk2msftngp13.phx.gbl...
下面,我是'我试图删除查询字符串名称& catID = 12的值。
我管理它来隔离RESULTS部分,但是我需要能够去除
查询字符串名称及其值,无论值是1 ,2或3
数字。
我选择隔离我将要删除的部分,因为我知道我可以把它拿走
并运行替换并获得正确的字符串虽然我硬编了qs
名称。

基本上,我想最终得到一个函数,我可以传递查询字符串和函数的名称将删除qs名称及其值

另一个问题,如果查询字符串名称和值是
查询字符串的唯一部分,我需要删除?在qs内。

任何帮助?
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?




<%

函数Remove_QS_Parameter(qs,p)

Dim retVal,重新

设置re =新RegExp

re.Pattern ="(\?|&)" &安培; p& " =。*?(& |



<%
Function Remove_QS_Parameter(qs, p)
Dim retVal, re
Set re = New RegExp
re.Pattern = "(\?|&)" & p & "=.*?(&|


)"

retVal = re.Replace(qs,"
)"
retVal = re.Replace(qs,"


2")

如果左(retVal,1)="&"然后retVal ="?" &安培;中(retVal,2)

Remove_QS_Parameter = retVal

结束函数


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>"

%>
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>"
%>