日期:2014-05-17 浏览次数:21136 次
<%
Class StringList
Private dict, strName, i
Private Sub Class_Initialize()
Set dict = CreateObject("Scripting.Dictionary")
i = 0
End Sub
Public Property Get Count()
Count = i
End Property
Public Property Let Name(newValue)
strName = newValue
End Property
Public Property Get Name()
Name = strName
End Property
Public Sub Add(strValue)
i = i + 1
dict.Add i, strValue
End Sub
Public Default Property Get ToString()
ToString = Me.Item(Empty)
End Property
Public Property Get Item(index)
If Not IsEmpty(index) And IsNumeric(index) Then
If index<1 Then Err.Raise -1, "StringList.Item", "下标越界"
If index>i Then Err.Raise -1, "StringList.Item", "下标越界"
Item = dict.Item(index)
ElseIf i>0 Then
Item = Join(dict.Items(), ", ")
End If
End Property
End Class
Function decodeURIComponent(str, cSet)
With Server.CreateObject("ADODB.Stream")
.Type = 2
.Charset = "iso-8859-1"
.Open
.WriteText UnEscape(Replace(str, "+", "%20"))
.Position = 0
.Charset = cSet
decodeURIComponent = .ReadText(-1)
.Close
End With
End Function
Function getParameter(name, cSet, dictionary)
Dim match : Set getParameter = New StringList : getParameter.Name = name
With New RegExp
.Pattern = "(?:^|&)" & Server.URLEncode(name) & "=([^&]*)"
.Global = True
For Each match In .Execute(dictionary)
getParameter.Add decodeURIComponent(match.Submatches.Item(0), cSet)
Next
End with
End Function
%>
<%=getParameter("p", "UTF-8", Request.QueryString)%><br />
<%=getParameter("p", "UTF-8", Request.QueryString).Count%><br />
<%=getParameter("p", "UTF-8", Request.QueryString).Item(1)%><br />
<!--
Dim p
Set p = getParameter("p", "UTF-8", Request.QueryString)
p.Count
p.Item(1)
p.Count 和 p.Item(index) 是在当出现同名参数时 使用.
如果不考虑同名参数,则代码可以进行大幅删减
-->