View Full Version : parse querystring
05-13-2007, 07:16 AM
if i'm returned (in a variable not a querystring)
something looking like a querystring
is there anyway to easily loop through the results?
05-13-2007, 01: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 />" )
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.
05-14-2007, 02: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.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.