ASP Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++DelphiFoxProJavaPerlPythonRubySQL ServerVBScript

ASP Examples

ASP String
ASP Byte Array
Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
S/MIME
Socket
Spider
RSA Encryption
Tar
Upload
XML
XMP
Zip Compression

More Examples...
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

URL Encode with utf-8 Encoding (or any Charset)

Demonstrates how to URL-encode a string or byte array using any charset. Note: This example uses the Chilkat Crypt ActiveX.

Note: Make sure you save your .ASP file using the iso-8859-1 character encoding. When non-usascii literal strings are present in an ASP script, this becomes important. See Also: ASP Code Pages and Literal Strings

Download Chilkat Crypt ActiveX

Download Chilkat Charset ActiveX

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<%
set crypt = Server.CreateObject("Chilkat.Crypt2")

'  Any string argument automatically begins the 30-day trial.
success = crypt.UnlockComponent("30-day trial")
If (success <> 1) Then
    Response.Write "Crypt component unlock failed" & "<br>"

End If

'  In utf-8, the é is represented in two bytes: C3 A9
s = "éé"

'  Use "None" so that no encryption/decryption is performed.
'  (we'll be using Chilkat Crypt for the encoding/decoding capabilities)
crypt.CryptAlgorithm = "none"

'  Set the desired encoding
crypt.EncodingMode = "url"

'  When strings are involved, use this charset:
crypt.Charset = "utf-8"

'  Other possible EncodingMode settings are:
'  "quoted-printable", "hex", and "url"

'  URL-encode
'  urlEncoded should contain: %C3%A9%C3%A9
urlEncoded = crypt.EncryptStringENC(s)

Response.Write Server.HTMLEncode( urlEncoded) & "<br>"

'  URL-decode
decoded = crypt.DecryptStringENC(urlEncoded)

Response.Write Server.HTMLEncode( decoded) & "<br>"

'  Let's do the same with an iso-8859-1 byte array:
'  In iso-8859-1, the é is represented in a single byte: E9
'  New and initialized CkByteArray
Dim x
x = x & ChrB(&HE9)
x = x & ChrB(&HE9)

'  Convert the byte array from iso-8859-1 to utf-8:
set cnv = Server.CreateObject("Chilkat.Charset2")

'  Any string argument automatically begins the 30-day trial.
success = cnv.UnlockComponent("30-day trial")
If (success <> 1) Then
    Response.Write "Charset component unlock failed" & "<br>"

End If

cnv.FromCharset = "iso-8859-1"
cnv.ToCharset = "utf-8"

'  
' Url-encode the utf-8 bytes:
Dim xUtf8
xUtf8 = cnv.ConvertData(x)
urlEncoded2 = crypt.EncryptBytesENC(xUtf8)

Response.Write Server.HTMLEncode( urlEncoded2) & "<br>"
%>
</body>
</html>

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.