Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Re-Encode a String (Hex, Base64, URL, etc)Demonstrates how to convert from one encoding to another. For example: base64 to hex, URL to base64, base64 to quoted-printable, etc. Note: The ReEncode method is unreleased at the time of this writing (08-April-2008) The next major Chilkat Crypt2 release after this date will include the ReEncode method.
CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @crypt int EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @crypt OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- Any string argument automatically begins the 30-day trial. DECLARE @success int EXEC sp_OAMethod @crypt, 'UnlockComponent', @success OUT, '30-day trial' IF @success <> 1 BEGIN PRINT 'Crypt component unlock failed' RETURN END DECLARE @hexStr nvarchar(4000) SELECT @hexStr = '41424344E0E1E2E3' DECLARE @fromEncoding nvarchar(4000) SELECT @fromEncoding = 'hex' DECLARE @toEncoding nvarchar(4000) SELECT @toEncoding = 'base64' -- Convert from hex to base64 DECLARE @base64 nvarchar(4000) EXEC sp_OAMethod @crypt, 'ReEncode', @base64 OUT, @hexStr, @fromEncoding, @toEncoding PRINT @base64 -- Now convert from base64 to quoted-printable: SELECT @fromEncoding = 'base64' SELECT @toEncoding = 'quoted-printable' DECLARE @qp nvarchar(4000) EXEC sp_OAMethod @crypt, 'ReEncode', @qp OUT, @base64, @fromEncoding, @toEncoding PRINT @qp -- Now convert from quoted-printable to URL: SELECT @fromEncoding = 'quoted-printable' SELECT @toEncoding = 'url' DECLARE @urlEnc nvarchar(4000) EXEC sp_OAMethod @crypt, 'ReEncode', @urlEnc OUT, @qp, @fromEncoding, @toEncoding PRINT @urlEnc -- Now convert from URL back to hex: SELECT @fromEncoding = 'url' SELECT @toEncoding = 'hex' EXEC sp_OAMethod @crypt, 'ReEncode', @hexStr OUT, @urlEnc, @fromEncoding, @toEncoding PRINT @hexStr -- The output of this program is: -- QUJDRODh4uM= -- ABCD=E0=E1=E2=E3 -- ABCD%E0%E1%E2%E3 -- 41424344E0E1E2E3 END GO |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.