如何压缩和解压缩字符串 [英] how to compress and decompress a string

查看:319
本文介绍了如何压缩和解压缩字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在寻找将172字符长字符串压缩成20个字符长字符串的技术(ASCII范围应在65-122之内) )。而且我必须反过来......安全性并不关心。



感谢您有价值的解决方案

解决方案

< blockquote>无法保证您可以将172个字符的字符串压缩为具有受限制的ASCII范围的20个字符 - 每个字符只允许6位,只允许36个不同的输入值。

如果您可以指定输入字符串只包含AZ和0-9然后你可以通过将字符折叠到其中来实现,但没有其他方法可以保证压缩到那个大小 - 压缩技术处理数据内容并利用它在那里找到的结构。



例如,AAAAAAAAAABBBBBBBBBB的简单压缩是A的计数,后面是B的计数,给你4个字节,但是相同应用于ABABABABABABABABABAB的算法会使字符串的长度加倍。


Hi,

I''m looking for technique which will compress a 172 character long string into 20 character long string (ASCII range should be within 65-122). And I must get the reverse ... security is not concerned.

Thanks for yr valuable solution

解决方案

There is no guarantee that you can compress a 172 character string into 20 characters with a restricted ASCII range - That only allows 6 bits per character which allows only 36 different input values.
If you can specify that the input string contains only A-Z and 0-9 then you could do it, by folding the characters into it, but there is no other way that can guarantee to compress to exactly that size - compression techniques work on the data content and exploit the structure it finds there.

For example, a simple compression of AAAAAAAAAABBBBBBBBBB would be a count of A followed by a count of B to give you 4 bytes, but the same algorithm applied to ABABABABABABABABABAB would double the length of the string.


这篇关于如何压缩和解压缩字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆