Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,456
    Thanks
    15
    Thanked 0 Times in 0 Posts

    parse querystring

    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?

  • #2
    New Coder
    Join Date
    Sep 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just loop the variable and split as you go

    Code:
    <%
    
    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.

  • #3
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •