ampersand in query string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mycoupons
    New Member
    • Mar 2010
    • 3

    ampersand in query string

    I am trying to capture querystring value into a string variable. But only the part before ampersand gets captured not the ampersand and the rest.

    c = Request.QuerySt ring["org"].Trim();

    Hovering on ".QueryStri ng" shows me "org=ab&cd"

    But "c" captures only part before ampersand , just "ab".

    How do I make this work?
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    The MSDN shows how to do this.
    Returns a new string in which all leading and trailing occurrences of a set of specified characters from the current string are removed.

    Comment

    • mycoupons
      New Member
      • Mar 2010
      • 3

      #3
      can you please explain?

      I need to capture the querystring value as it is because that is going to be my input parameter for a sql stored proc. But anything before ampersand is not being captured.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        In query strings the "&" is used as a delimiter between variables.
        So you would have:

        "var1=something &var2=someth ing else&var3=..."

        In your case you have an & in the middle of a string. When the server tries to retrieve the variables from the query string it's taking what ever comes after the "&" as a variable name and it's looking for the "="....

        You cannot have an "&" your strings.

        Instead you need to convert the "&" a "query string safe" value that represents the "&". Try using the ACII value instead of the actual "&" when creating your query string.

        -Frinny

        Comment

        Working...