{"id":170,"date":"2009-04-13T07:31:25","date_gmt":"2009-04-13T14:31:25","guid":{"rendered":"http:\/\/cknotes.com\/?p=170"},"modified":"2009-04-13T07:31:25","modified_gmt":"2009-04-13T14:31:25","slug":"vbnet-compress-string-to-byte-array","status":"publish","type":"post","link":"https:\/\/cknotes.com\/vbnet-compress-string-to-byte-array\/","title":{"rendered":"VB.NET Compress String to Byte Array"},"content":{"rendered":"<p>Demonstrates how to use Chilkat.Compression to compress a string to a byte array:<\/p>\n<pre>    Private Sub CompressStringToBytes()\r\n\r\n        Dim compress As New Chilkat.Compression()\r\n\r\n        '  Any string argument automatically begins a 30-day trial.\r\n        Dim success As Boolean\r\n        success = compress.UnlockComponent(\"30-day trial\")\r\n        If (success &lt;&gt; True) Then\r\n            MsgBox(\"Compression component unlock failed\")\r\n            Exit Sub\r\n        End If\r\n\r\n        ' Use the \"deflate\" algorithm, which is the algorithm used\r\n        ' for .zip.  Other algorithms are \"lzw\", \"bzip2\", and \"ppmd\"\r\n        compress.Algorithm = \"deflate\"\r\n\r\n        Dim strData As String\r\n\r\n        '  Create a string to compress:\r\n        strData = \"hellohellohellohellohellohellohellohellohellohello\"\r\n        MessageBox.Show(\"Uncompressed size: \" &amp; strData.Length.ToString())\r\n\r\n        '  Tell the component to convert to\r\n        '  ansi (1-byte\/char) prior to compression:\r\n        compress.Charset = \"ansi\"\r\n\r\n        Dim compressedData As Byte()\r\n        compressedData = compress.CompressString(strData)\r\n        MessageBox.Show(\"Compressed size: \" &amp; compressedData.Length.ToString())\r\n\r\n        ' Decompress:\r\n        Dim origStr As String\r\n        origStr = compress.DecompressString(compressedData)\r\n        MessageBox.Show(origStr)\r\n\r\n    End Sub\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Demonstrates how to use Chilkat.Compression to compress a string to a byte array: Private Sub CompressStringToBytes() Dim compress As New Chilkat.Compression() &#8216; Any string argument automatically begins a 30-day trial. Dim success As Boolean success = compress.UnlockComponent(&#8220;30-day trial&#8221;) If (success &lt;&gt; True) Then MsgBox(&#8220;Compression component unlock failed&#8221;) Exit Sub End If &#8216; Use the &#8220;deflate&#8221; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[189,504,505],"class_list":["post-170","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-compress","tag-compression","tag-vbnet"],"_links":{"self":[{"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts\/170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/comments?post=170"}],"version-history":[{"count":0,"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts\/170\/revisions"}],"wp:attachment":[{"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/media?parent=170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/categories?post=170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/tags?post=170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}