哪位有字符串压缩的,效率比较高的(100)

  • 主题发起人 主题发起人 kxgkxg
  • 开始时间 开始时间
K

kxgkxg

Unregistered / Unconfirmed
GUEST, unregistred user!
哪位有字符串压缩的,效率比较高的,请提供一下function UnzipStr2Str(const S: String):String;function zipStr2Str(const S: String):String;
 
用Zlib吧,Delphi自带。也可以去官网下载C的,开源,Delphi下提供一个PAS文件调用 uses ...,Zlib; function zipStr2Str(Str: string): string; var instream: Tmemorystream; zstream: Tcompressionstream; outstream: Tmemorystream; size: integer; begin instream := Tmemorystream.Create; try instream.Write(Str[1], Length(Str)); if instream.Size = 0 then exit; size := instream.size; outstream := Tmemorystream.create; zstream := Tcompressionstream.Create(clmax, outstream); try instream.SaveToStream(zstream); zstream.free; outstream.Position := 0; instream.clear; instream.WriteBuffer(size, sizeof(size)); instream.CopyFrom(outstream, 0); instream.Position := 0; SetLength(Result, instream.Size); instream.ReadBuffer(Result[1], instream.Size); finally outstream.free; end; finally instream.Free; end; end; function UnzipStr2Str(Str: string): string; var instream: Tmemorystream; zstream: Tdecompressionstream; outstream: Tmemorystream; size: integer; buffer: pchar; begin instream := Tmemorystream.Create; try instream.Write(Str[1], Length(Str)); if instream.Size = 0 then exit; instream.Position := 0; instream.ReadBuffer(size, sizeof(size)); getmem(buffer, size); outstream := Tmemorystream.create; zstream := Tdecompressionstream.Create(instream); try zstream.Readbuffer(buffer^, size); outstream.WriteBuffer(buffer^, size); outstream.Position := 0; instream.clear; instream.CopyFrom(outstream, 0); instream.Position := 0; SetLength(Result, instream.Size); instream.ReadBuffer(Result[1], instream.Size); finally zstream.free; outstream.Free; freemem(buffer); end; finally instream.Free; end; end;
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
911
SUNSTONE的Delphi笔记
S
后退
顶部