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
(DataFlex) Compress and Decompress a StringDemonstrates how to compress and decompress a string.
Use ChilkatAx-win32.pkg Procedure Test Boolean iSuccess Handle hoSb Integer i Handle hoCompress Variant hoCompressedBytes String sCompressedBase64 String sDecompressedString String sTemp1 // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatStringBuilder)) To hoSb If (Not(IsComObjectCreated(hoSb))) Begin Send CreateComObject of hoSb End For i From 1 To 20 Get ComAppend Of hoSb "This is the original uncompressed string." + (character(13)) + (character(10)) To iSuccess Loop Get Create (RefClass(cComChilkatCompression)) To hoCompress If (Not(IsComObjectCreated(hoCompress))) Begin Send CreateComObject of hoCompress End Set ComAlgorithm Of hoCompress To "deflate" // Indicate that the utf-8 byte representation of the string should be compressed. Set ComCharset Of hoCompress To "utf-8" Get ComGetAsString Of hoSb To sTemp1 Get ComCompressString Of hoCompress sTemp1 To hoCompressedBytes // If the compressed data is desired in string format, then get the base64 representation of the bytes. Set ComEncodingMode Of hoCompress To "base64" Get ComGetAsString Of hoSb To sTemp1 Get ComCompressStringENC Of hoCompress sTemp1 To sCompressedBase64 Showln "Compressed Bytes as Base64: " sCompressedBase64 // Now decompress... Get ComDecompressString Of hoCompress vCompressedBytes To sDecompressedString Showln "The original string after decompressing from binary compressed data:" Showln sDecompressedString // To decompress from Base64... Set ComEncodingMode Of hoCompress To "base64" Get ComDecompressStringENC Of hoCompress sCompressedBase64 To sDecompressedString Showln "The original string after decompressing from Base64:" Showln sDecompressedString End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.