...

View Full Version : parse querystring



esthera
05-13-2007, 06:16 AM
if i'm returned (in a variable not a querystring)

something looking like a querystring

response=10&cc=dfkj&id=77

is there anyway to easily loop through the results?

printf
05-13-2007, 12:29 PM
Just loop the variable and split as you go


<%

dim my_variable, my_pair, my_item, my_value

my_variable = "a=b&c=d&e=f"

my_pair = split ( my_variable, chr ( 38 ) ) ' split at -> &

for each my_item in my_pair

my_value = split ( my_item, chr ( 61 ) ) ' split at -> =

if my_value(0) = "c" then

response.write ( "value for variable <strong>c</strong>: " & my_value(1) & "<br />" )

end if

next

%>

If you need them to be dynamic, then use eval or execute, but only do that if you known how to protect the eval function from dangerous input that could be in the variables being evaluated or executed. But I myself wouldn't use eval or execute, because there are always safer ways to do it.

ghell
05-14-2007, 01:49 AM
If you wish to use it as you use querystrings, use split(input, "&") to get each element, then Mid, Left or Right the first index of "=" to get what is to the left of the first = and what is to the right, then create a Dictionary object of your key/value pairs.

I'm assuming there is no easy way to simply create a dictionary from a string. If there is then I don't know about it, but it would be useful in this situation.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum