title: ASP URLDecode - Incorrect Conversion
body: <p>I have a website where google pics up some links on my site and sends throught the following URL</p>
  
  <p><a href="http://www.globalpropertyonline.net/test.asp?town=gand%EDa" rel="nofollow noreferrer">http://www.globalpropertyonline.net/test.asp?town=gand%EDa</a></p>
  
  <p>I have one of the URLDecode Functions I found on the net to Decode the %ED</p>
  
  <p>However, this seems not to be working the correct way.</p>
  
  <p>The %ED should be this : í</p>
  
  <p>So when I Decode it the word should be gandía</p>
  
  <p>But instead I get the following word : gandï¿½a</p>
  
  <p>On the page where google gets the link, it is displayed correctly as gandía but it prompts me in webmaster tools that the following link has a error 500 and this is because when I try to take this name and sends it to the MYSQL query it crash with error 500 but if I would have had gandía then it worked !</p>
  
  <p>So, my main problem is that I am getting the %ED sent as URLEncode as it seems and I want to Decode it before I send it to my database query.</p>
  
  <p>In my ASP Page I am using UTF-8 Encodeing as follows.</p>
  
  <pre><code>&lt;%@ CodePage=65001 Language="VBScript"%&gt; 
  &lt;%
  Response.CodePage = 65001
  Response.CharSet = "utf-8"
  </code></pre>
  
  <p>This is the Code I am using to Decode it but instead if getting the gandía I get this : gandï¿½a</p>
  
  <p>any help will be much apreciated</p>
  
  <pre><code>&lt;%@ CodePage=65001 Language="VBScript"%&gt; 
  &lt;%
  Response.CodePage = 65001
  Response.CharSet = "utf-8" 
  
  MyTown = Request("town")
  
  response.write URLDecode(MyTown)
  
  
      Function URLDecode(str) 
          str = Replace(str, "+", " ") 
          For i = 1 To Len(str) 
              sT = Mid(str, i, 1) 
              If sT = "%" Then 
                  If i+2 &lt; Len(str) Then 
                      sR = sR &amp; _ 
                          Chr(CLng("&amp;H" &amp; Mid(str, i+1, 2))) 
                      i = i+2 
                  End If 
              Else 
                  sR = sR &amp; sT 
              End If 
          Next 
          URLDecode = sR 
      End Function
  
  %&gt;
  </code></pre>