VB.NET 压缩 解压缩 字符串
如何在 VB.NET 中压缩/解压缩字符串? 我正在尝试通过网络发送长字符串,并在发送之前需要它们尽可能小。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 GzipStream。
这是一个例子:
2年后编辑...
这对我来说不太有效,也许是因为我需要将数据存储在字节数组中。这适用于压缩:
然后对于解压缩,我只是将字节数组传递到 mem2 的构造函数而不是 mem.ToArray 中。
You could use GzipStream.
Here is an example:
edit 2 years later...
That didn't quite work for me, perhaps because I needed to store the data in a byte array. This worked for Compress:
Then for Decompress I just passed the byte array into the constructor of mem2 instead of mem.ToArray.
可以通过 GZipStream 传递它MemoryStream,然后检索压缩流并将其发送通过网络。压缩不是那么好,但它快速且易于编码。
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.
您还可以查看 Xceed 库。它比 GZipstream 速度更快,压缩效果也更好。
You can also take a look at Xceed library. Its faster and the it also compresses a lot better than GZipstream.