Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
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 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <% set crypt = Server.CreateObject("Chilkat_9_5_0.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_9_5_0.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> |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.