+ Reply to Thread
Results 1 to 2 of 2

Thread: Simple string compression/Decompression

  1. #1
    jwh
    jwh is offline VB.NET Forum Genius jwh will become famous soon enough
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Aug 2006
    Age
    26
    Posts
    155
    Reputation
    63

    Default Simple string compression/Decompression

    Hi guys.

    Is there any simple way of making 2 functions, one to compress a string, one to decompress said string?

    Over the past few weeks I have spent too much time messing about with libraries such as zsharplib or whatever it is, and my project cannot afford any more time to put it bluntly!

    All the compression examples I found take in and spit out byte arrays, which I can never seem to get working!!!


    Hope someone can help...
    There are 10 types of people in this world.... those who know binary, and those who don't.

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Age
    37
    Posts
    10,843
    Reputation
    1443

    Default

    Here's an example using System.IO.Compression, substitute MemoryStream with FileStream for file storage:
    Code:
    'compress
    Dim mem As New IO.MemoryStream
    Dim gz As New System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Compress)
    Dim sw As New IO.StreamWriter(gz)
    sw.WriteLine("hello compression")
    sw.Close()
     
    'decompress
    Dim mem2 As New IO.MemoryStream(mem.ToArray)
    gz = New System.IO.Compression.GZipStream(mem2, IO.Compression.CompressionMode.Decompress)
    Dim sr As New IO.StreamReader(gz)
    MsgBox(sr.ReadLine)
    sr.Close()

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts