QueryStringBuilder Function:
This function replaces or add specified variables In the existing QUERY_STRING
Description:
This function replaces or add specified variables In the existing QUERY_STRING Companion Function: StringIndex()
Syntax:
QueryStringBuilder(Request.ServerVariables("QUERY_STRING"), "var1=123&var3=456&var4=444")
Example:
<%
'--- Current Query String: http://www.example.com/mypage.asp?var1=111&var2=222&var3=333 '--- Usage: QueryStringBuilder(Request.ServerVariables("QUERY_STRING"), "var1=123&var3=456&var4=444") '--- Resulting Query String: http://www.example.com/mypage.asp?var1=123&var2=222&var3=456&var4=444
%>
ASP Source Code:
<%
'--------------------------------------------------- Function StringIndex(sArray, sString) '--- Returns the location (index) of a row that *contains* specified String Dim i StringIndex = -1 For i = 0 To UBound(sArray) if Instr(sArray(i), sString) Then StringIndex = i Next End Function '--------------------------------------------------- Function QueryStringBuilder(sCurrentQueryString, sNewVariableList) '--- This function replaces or add specified variables In the existing QUERY_STRING '--- Companion Function: StringIndex() '--- Current Query String: http://www.example.com/mypage.asp?var1=111&var2=222&var3=333 '--- Usage: QueryStringBuilder(Request.ServerVariables("QUERY_STRING"), "var1=123&var3=456&var4=444") '--- Resulting Query String: http://www.example.com/mypage.asp?var1=123&var2=222&var3=456&var4=444 Dim i sOrigParts = Split(sCurrentQueryString, "&") sNewParts = Split(sNewVariableList, "&") '--- First replace existing values with new ones For i = 0 To UBound(sOrigParts) part = Split(sOrigParts(i), "=") If StringIndex(sNewParts, part(0) & "=") >= 0 Then sNewQueryString = sNewQueryString & sNewParts(StringIndex(sNewParts, part(0) & "=")) & "&" Else sNewQueryString = sNewQueryString & part(0) & "=" & part(1) & "&" End if Next '--- Now add values that weren't present before For i = 0 To UBound(sNewParts) part = Split(sNewParts(i), "=") If StringIndex(sOrigParts, part(0) & "=") < 0 Then sNewQueryString = sNewQueryString & part(0) & "=" & part(1) & "&" End if Next QueryStringBuilder = Left(sNewQueryString, Len(sNewQueryString)-1) End Function
%>
|