Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Classic ASP Examples

Web API Categories

ASN.1
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

ASP Charset Convert Tutorial

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Convert Unicode to utf-8, then convert utf-8 to iso-8859-1.

<% @CodePage = 65001 %>
<% Response.CodePage = 28591 %> 

<%
' Convert utf-8 (code page 6500) to iso-8859-1 (code page 28591)
'
' IMPORTANT: Remember to save this .asp files in the utf-8 character encoding.
' IMPORTANT: Remember to save this .asp files in the utf-8 character encoding.
' IMPORTANT: Remember to save this .asp files in the utf-8 character encoding.

' The first directive, "@CodePage" is the code page of the ASP file.
' When you save the .asp file using your editor, save it in this code page.
' This is the charset used for literal strings within your ASP scripting.
' 
' The Response.CodePage directive indicates the charset encoding emitted
' by Response.Write.  

' The charset specified in the <meta> tag, as shown below, must match
' the Response.CodePage.  
%>

<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body>
<%

myStr = "eèéêë"
' myStr is a String.  Strings in ASP are Unicode (2 bytes/char).
' This particular .asp file is saved in the utf-8 encoding (our @CodePage is utf-8).
' Therefore, the ASP scripting engine converts the literal string from utf-8 to
' Unicode.  (utf-8 is actually the multibyte encoding of Unicode, but it is a different
' character encoding than the 2-byte/char Unicode)

' Create a Chilkat Charset object to convert and examine the character data.
set cc = Server.CreateObject("Chilkat_9_5_0.Charset2")
cc.UnlockComponent "Anything for 30-day trial"

' Turn on "SaveLast" so we can see what happened...
cc.SaveLast = 1

cc.ToCharset = "utf-8"
' If your source data is a String (i.e. not a byte array / Variant) it is Unicode.
' The string type in ASP is *always* Unicode (i.e. ucs-2).
utf8Bytes = cc.ConvertFromUnicode(myStr)

' Examine the bytes passed to the converter and the bytes returned:
inHexStr = cc.LastInputAsHex
outHexStr = cc.LastOutputAsHex

Response.Write "<b>Unicode to utf-8 conversion:</b><br>"
Response.Write "Input: " + inHexStr + "<br>"
Response.Write "Output: " + outHexStr + "<p>"

' This is the output:
' Input: 6500 E800 E900 EA00 EB00
' Output: 65C3 A8C3 A9C3 AAC3 AB

' We can clearly see that the input was Unicode (2 bytes/char).
' The output is utf-8.  The individual characters are: 65 C3A8 C3A9 C3AA C3AB

' Now that we have utf-8, convert it to iso-8859-1:
cc.FromCharset = "utf-8"
cc.ToCharset = "iso-8859-1"
isoBytes = cc.ConvertData(utf8Bytes)

' Look at the results:
inHexStr = cc.LastInputAsHex
outHexStr = cc.LastOutputAsHex
Response.Write "<b>utf-8 to iso-8859-1 conversion:</b><br>"
Response.Write "Input: " + inHexStr + "<br>"
Response.Write "Output: " + outHexStr + "<p>"

' This is the output:
' Input: 65C3 A8C3 A9C3 AAC3 AB
' Output: 65E8 E9EA EB

' The iso-8859-1 charset encoding is 1-byte/character, and we can see that it
' is correct in the output.

' This ASP page's Response Code page is iso-8859-1, so we can emit the bytes
' directly with Response.BinaryWrite...
Response.Write "This is emitted with Response.BinaryWrite: "
Response.BinaryWrite isoBytes
Response.Write "<p>"

%>
</body>
</html>

 

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