Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jonas Høiby 62 posts 53 karma points
    Oct 14, 2009 @ 10:23
    Jonas Høiby
    0

    string manipulation - if exists ..

    hi guys .. 

     

    i need to check a string (my querystring) for a word and if its there i need to replace that + its value with a new value ..

     

    Example:

     

    http://test.com?page=1&topx=25&country=denmark&area=jutland

     

    i extract the querystring so i get:

    page=1&topx=25&country=denmark&area=jutland

     

    then its here i need to check if ex 'area' exists - and if it comes back true - then i need to replace its value with a new value ...

     

    so ill end up with the result:

    page=1&topx=25&country=denmark&area=fyn

     

    must be dynamic so i can check which parameter i want .. :-)

     

    thank .. :-)

     

  • dandrayne 1138 posts 2262 karma points
    Oct 14, 2009 @ 10:28
    dandrayne
    0

    You can request individual url paramters via http://our.umbraco.org/wiki/reference/umbracolibrary/requestquerystring and replace with http://our.umbraco.org/wiki/reference/umbracolibrary/replace. ; That should do what you want

    Dan

     

  • Jonas Høiby 62 posts 53 karma points
    Oct 14, 2009 @ 10:46
    Jonas Høiby
    0

    and if I dont know which parameters will be in my querystring or what position they will be at? :-)

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Oct 14, 2009 @ 11:17
    Dirk De Grave
    0

    Position or a querystring param doesn't matter, and if you don't know the parameter's name, hmm, that'll be pretty hard to deal with it!

    If you need the names & values of all querystring params, write a small xslt extension that gets the querystring from the current request.

     

    Cheers,

    /Dirk

     

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Oct 14, 2009 @ 12:01
    Lee Kelleher
    0

    Hi Jonas,

    You will need an XSLT extension, (or custom function) to perform the following logic:

    Pass the 'key' and 'replacementValue' to a function.
    
    Copy the QueryString object to a NameValueCollection
    
    Check if the NameValueCollection has the 'key'. If so, then replace the current value with the 'replacementValue'.
    
    Then convert the NameValueCollection back to querystring type of String.

    This is just pseudo-code, as I don't have time to provide a full function/method.

    You are in luck with a few things... I have written a couple of blog posts about how to handle NameValueCollections.

    Making Request.QueryString writable (by clone/copy)

    How to convert NameValueCollection to a (Query) String

    Good luck!

    Cheers, Lee.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies