(Classic ASP) URL Encoding and Decoding
Demonstrates URL encoding and decoding.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
' To URL encoding a string:
s = "Why a > b?"
' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.StringBuilder")
set sb = Server.CreateObject("Chilkat.StringBuilder")
success = sb.Append(s)
' URL encode the string.
success = sb.Encode("url","utf-8")
' Show the URL encoded string:
sEncoded = sb.GetAsString()
Response.Write "<pre>" & Server.HTMLEncode( sEncoded) & "</pre>"
' The result is: Why%20a%20%3E%20b%3F
' If you prefer "+" instead of "%20" for SPACE chars:
numReplaced = sb.Replace("%20","+")
Response.Write "<pre>" & Server.HTMLEncode( sb.GetAsString()) & "</pre>"
' Output is: Why+a+%3E+b%3F
' To decode:
success = sb.Decode("url","utf-8")
Response.Write "<pre>" & Server.HTMLEncode( sb.GetAsString()) & "</pre>"
' Result is: Why a > b?
%>
</body>
</html>
|