• I removed the www from the URL, please update your bookmarks and pay attention to the bottom of the screen if using Google Chrome to allow push notifications again.

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...
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,276
Location
Norway
Programming Experience
10+
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()
 
Top Bottom