Simple string compression/Decompression

jwh

Well-known member
Joined
Aug 18, 2006
Messages
155
Programming Experience
3-5
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...
 
Here's an example using System.IO.Compression, substitute MemoryStream with FileStream for file storage:
VB.NET:
'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()
 
Back
Top