Forum Moderators: open

Message Too Old, No Replies

Newbie question, asp case statements

Ampersand in asp code

         

pinto172

5:50 pm on Feb 25, 2008 (gmt 0)

10+ Year Member



Alright so what I want this code to do is display certain text only on certain pages.

I got it to work for the most part. The problem I have is there is some pages that have the Ampersand symbol or the & in it.

The ones that do have that sign when I request to pull the text for that page it doesn't work and I know its because of the & symbol.

Here is my example:

case "test&test4"
response.write "skdkdksdkskdksd"

so my question is how do i make it work?

mattur

6:48 pm on Mar 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could it be an encoded ampersand "&" rather than a simple "&"?

vfoo

10:40 pm on Mar 5, 2008 (gmt 0)

10+ Year Member



Newbie to the forum here (came across this looking for something else) but...

I'm assuming Classic ASP? [looks like it even though .net forum?]
'Set the Name/Location of the page
'Example will return "/index.asp?a=1&b=1"
PageName = Request.ServerVariables("URL")
If Request.ServerVariables("Query_String") <> "" Then
PageName = PageName & "?" & Request.ServerVariables("Query_String")
End If

Select CASE PageName
CASE "/index.asp?a=1"
Response.WRite "Foo ... " & PageName
CASE "/other.asp?a=2&b=3"
Response.Write "Foo2 ... " & PageName
CASE ELSE
Response.Write "Other / Unknown"
End Select

Of course this is a bad idea... Depending on your server setup anyone can modify a QueryString and therefore your test would fail.

You could test for specific querystrings (very common) or test for the individual name of the page (in which case "URL" server variable works handily)

HTH
vfoo

beauzero

9:15 pm on Mar 13, 2008 (gmt 0)

10+ Year Member



There is a url encode or decode either one will work...either encode your "case somestring" where some string needs to be encoded or decode the incoming url before you compare it in your case statement.