Hello,
How do I compress/decompress a string in VB.NET ? I am trying to send long string through the Network and need them to be as small as possible before sending.
Thanks
Hello,
How do I compress/decompress a string in VB.NET ? I am trying to send long string through the Network and need them to be as small as possible before sending.
Thanks
Could pass it through a GZipStream over a MemoryStream, then retrieve the compressed stream to send it over the network. Not that great compression, but it's fast and easy to code.
You could use GzipStream.
Here is an example:
//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()
You can also take a look at Xceed library. Its faster and the it also compresses a lot better than GZipstream.