' ' ASP/VBScript Dictionary extract ' Author: WangYe ' For more information please visit ' ' This code is distributed under the BSD license ' ' collection 集合或者字典,可以通過For Each訪問的 ' Request.Form 或者 Request.QueryString ' specified 指定必須存在的屬性,假如該屬性不存在,將自動創建一個 ' prefix 每個屬性的前綴修飾 ' callback 對于集合或者字典的每個元素(key-value)的值進行函數調用 ' 函數原型: ' Function filter(key, value) ' filter = value ' End If ' 最終值將以該函數返回的值為準 ' Function extract(collection, ByVal specified, prefix, callback) Dim VarName, VarValue, DynObj, searchKey specified = "," & Replace(specified, " ", "") & ","
Set DynObj = New DynamicObject For Each key In collection searchKey = "," & key & "," If InStr(1, specified, searchKey, 1)>0 Then specified = Replace(specified, searchKey, "") If Left(specified, 1) <> "," Then specified = "," & specified End If If Right(specified, 1) <> "," Then specified = specified & "," End If End If
VarName = prefix & key
VarValue = collection(key) If callback<>"" Then VarValue = GetRef(callback)(key, VarValue) End If