在Delphi中如果需要对字符串进行压缩与解压缩是非常简单的事,只需要uses一下zlib单元即可.

ZCompressStr:压缩字符串,传人字符串,返回TBytes;

ZDecompressStr:解压字符串,传人TBytes,返回字符串;

定义变量:

 

var
  str:String;

  tb:TBytes; 

  st:TBytesStream;

 

 压缩:

//返回压缩结果 
  tb:=ZCompressStr(str); 

//可以将结果转换为流数据

 st:=TBytesStream.Create(tb);
  

解压缩:

//从TBytes中解压

str:=ZDecompressStr(tb);

//从流中解压

st:=TBytesStream.Create(tb);

str:=ZDecompressStr(st.Bytes);

posted on 2010-01-25 09:55  garfieldtom  阅读(3451)  评论(0编辑  收藏  举报