我已经将一个非常大的QueryString保存到MS SQL列中,字符串看起来像这样:
&s1=Toledo,OH&s2=Chicago,IL&s3=Madison,WI.....and so on...
我希望能够在ASP-Classic中做到这样的事情:
Dim s1,s2,s3,s4....and son on...
s1="Toledo,OH"
s2="Chicago,IL"
s3="Madison,WI"
.....and son on.....
我希望能像调用QueryString一样调用它们,例如QueryString调用是Request.QueryString(“s1”),或者我可以使用Do并循环所有的Request.QueryString(“s”& amp; ; i)直到query =“”然后我会退出Do。
但是,如果我将query.string保存到MS DB列中,我将如何实现所有这些?
请帮忙,
谢谢...
我一直收到这个错误:变量未定义:'s1',我在这里做错了什么?
Function qq(s)
qq = """" & s & """"
End Function ' qq
Dim sInp : sInp = objRSConnSAVE("QSTRING")
Dim dicData : Set dicData = Server.CreateObject("Scripting.Dictionary")
Dim oRE : Set oRE = New RegExp
oRE.Global = True
oRE.Pattern = "&([^=]+)=([^&]*)"
Dim oMTS : Set oMTS = oRE.Execute(sInp)
Dim oMT
For Each oMT In oMTS
dicData(oMT.SubMatches(0)) = oMT.SubMatches(1)
Next
Dim sKey, sValue
For Each sKey In dicData.Keys
sValue = dicData(sKey)
'''// Response.write qq(sKey) & "=>" & qq(sValue)
Next
Response.write "TEST" & s1
'// I even tried Response.write "TEST" & s(1) same error, how do I call it ?
答案 0 :(得分:2)
使用RegExp(而不是Split)和字典(而不是一堆标量变量):
Dim sInp : sInp = "&s1=Toledo,OH&s2=Chicago,IL&s3=Madison,WI"
Dim dicData : Set dicData = CreateObject("Scripting.Dictionary")
Dim oRE : Set oRE = New RegExp
oRE.Global = True
oRE.Pattern = "&([^=]+)=([^&]*)"
Dim oMTS : Set oMTS = oRE.Execute(sInp)
Dim oMT
For Each oMT In oMTS
dicData(oMT.SubMatches(0)) = oMT.SubMatches(1)
Next
Dim sKey, sValue
For Each sKey In dicData.Keys
sValue = dicData(sKey)
WScript.Echo qq(sKey), "=>", qq(sValue)
Next
输出:
"s1" => "Toledo,OH"
"s2" => "Chicago,IL"
"s3" => "Madison,WI"
<强>更新强>
qq()是一个双引号字符串的函数:
Function qq(s)
qq = """" & s & """"
End Function ' qq
更新II:
使用dicData("s2")
获取伊利诺伊州芝加哥
答案 1 :(得分:1)
为什么要声明s1
,s2
等?
创建一个要用作数组的变量,并使用&符号(Split
)对字符串使用&
函数,然后当需要引用单个行时,再将其拆分等号(=
)。
例如:
arMyArray = Split(YourQueryString, "&")
for i = 0 to uBound(arMyArray)
key = Split(arMyArray(i), "=")(0)
cityAndState = Split(arMyArray(i), "=")(1)
next