Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(MFC) Compress and Decompress a StringDemonstrates how to compress and decompress a string.
#include <CkStringBuilder.h> #include <CkCompression.h> #include <CkByteData.h> void ChilkatSample(void) { CkString strOut; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. bool success; CkStringBuilder sb; int i; for (i = 1; i <= 20; i++) { sb.Append("This is the original uncompressed string.\r\n"); } CkCompression compress; compress.put_Algorithm("deflate"); // Indicate that the utf-8 byte representation of the string should be compressed. compress.put_Charset("utf-8"); CkByteData compressedBytes; success = compress.CompressString(sb.getAsString(),compressedBytes); // If the compressed data is desired in string format, then get the base64 representation of the bytes. compress.put_EncodingMode("base64"); const char *compressedBase64 = compress.compressStringENC(sb.getAsString()); strOut.append("Compressed Bytes as Base64: "); strOut.append(compressedBase64); strOut.append("\r\n"); // Now decompress... const char *decompressedString = compress.decompressString(compressedBytes); strOut.append("The original string after decompressing from binary compressed data:"); strOut.append("\r\n"); strOut.append(decompressedString); strOut.append("\r\n"); // To decompress from Base64... compress.put_EncodingMode("base64"); decompressedString = compress.decompressStringENC(compressedBase64); strOut.append("The original string after decompressing from Base64:"); strOut.append("\r\n"); strOut.append(decompressedString); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.