|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Compress a stringI have several *long* strings (see bottom of post for an example) which I will be sending across a network. Therefore, I want to compress them for speed and because later they will be stored in a DB. I found this code here http://abstractvb.com/code.asp?A=931 but it doesn't seem to give me a particuarly good level of compression it seems. As you can see in the article below, there is a lot of repitition. So I was hoping that someone here could tell me that either the code at the link is correct, what is wrong with it or of another method I could use to compress my string(s). TIA AAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQmnOxFPsd4hT7HeIU+x3iEfdA4hb7HeIR9xLiFfsd4hH3QuIb+x3iB/NA4hb7HeKX80DiHfsd4hT7HOJY+x3iEfd94hD7HeIR90fiFfsd4lJpY2gU+x3iAAAAAAAAAAAAAAAAAAAAAFBFAABMAQMAeaGCQQAAAAAAAAAA4AAPAQsBBwoAEAAAABIAAAAAAADjGgAAABAAAAAgAAAAAEAAABAAAAACAAAEAAAAAAAAAAQAAAAAAAAAAEAAAAAEAADXjAAAAwAAAAAAEAAAEAAAAAAQAAAQAAAAAAAAEAAAAAAAAAAAAAAAlCMAAIwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAhAAAcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4CIAAEgAAAAAAAAAAAAAAAAgAABAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALnRleHQAAAA0DgAAABAAAAAQAAAABAAAAAAAAAAAAAAAAAAAIAAAYC5yZGF0YQAAtAoAAAAgAAAADAAAABQAAAAAAAAAAAAAAAAAAEAAAEAuZGF0YQAAAEQFAAAAMAAAAAIAAAAgAAAAAAAAAAAAAAAAAABAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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WbHBwAAi1wkSIXbD4SoAAAAaHAhQABoXCFAAP8VbCBAAFD/FXAgQABmxwMAAGaDPwCL8A+EgAAAAIX2dEKNRCQQUGgAAAEAagBqAFdqAP/WhcB0F41MJBBRaAAAAgBqAGoAV2oA/9aFwHVOi1QkEIsCUFP/1YtMJBiDxAhR6zVoIDBAAFdqAOg3BQAAhcB0EWggMEAAV2oA6CAFAACFwHUYixUgMEAAUlP/1aEgMEAAg8QIUOj+BAAAi0wkNF9eXTPAW+hUCAAAg8Qow8zMzMzMzMzMzMzMg+wYVsdEJAQEAAAA/xU0IUAAi/CF9nUFXoPEGMNX/xVkIEAAUP8VMCFAAIv4hf90SmoBjUQkEFD/FRwgQABqAGoAagGNTCQYUf8VICBAAI1UJAxSjUQkDFBWizU4IUAA/9aFwHUd/xVoIEAAUGiwIUAA/xWUIEAAg8QIXzPAXoPEGMONTCQMUY1UJAxSV//WhcB1Hf8VaCBAAFBogCFAAP8VlCBAAIPECF8zwF6DxBjDX7gBAAAAXoPEGMPMzMzMg+wYU1ZXavb/FVwgQACLNWAgQACL+LsBAAAA6wONSQCNRCQMUFONTCQYUVf/1oXAdO6LRCQMhcB25mY5XCQQdd+LRCQUhcB012aLRCQeZoXAdM1fXluDxBjDzMzMzMzMUVNVVldq9v8VXCBAAItMJBiL6KGkIE Maybe something like RLE compression?
Meelis Show quoteHide quote "Hugh Janus" <my-junk-acco***@hotmail.com> wrote in message news:1150716129.316513.278700@i40g2000cwc.googlegroups.com... > Hi all, > > I have several *long* strings (see bottom of post for an example) which > I will be sending across a network. Therefore, I want to compress them > for speed and because later they will be stored in a DB. > I found this code here http://abstractvb.com/code.asp?A=931 but it > doesn't seem to give me a particuarly good level of compression it > seems. As you can see in the article below, there is a lot of > repitition. So I was hoping that someone here could tell me that > either the code at the link is correct, what is wrong with it or of > another method I could use to compress my string(s). > > > TIA > > > > > > AAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gR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wYVsdEJAQEAAAA/xU0IUAAi/CF9nUFXoPEGMNX/xVkIEAAUP8VMCFAAIv4hf90SmoBjUQkEFD/FRwgQABqAGoAagGNTCQYUf8VICBAAI1UJAxSjUQkDFBWizU4IUAA/9aFwHUd/xVoIEAAUGiwIUAA/xWUIEAAg8QIXzPAXoPEGMONTCQMUY1UJAxSV//WhcB1Hf8VaCBAAFBogCFAAP8VlCBAAIPECF8zwF6DxBjDX7gBAAAAXoPEGMPMzMzMg+wYU1ZXavb/FVwgQACLNWAgQACL+LsBAAAA6wONSQCNRCQMUFONTCQYUVf/1oXAdO6LRCQMhcB25mY5XCQQdd+LRCQUhcB012aLRCQeZoXAdM1fXluDxBjDzMzMzMzMUVNVVldq9v8VXCBAAItMJBiL6KGkIE > Meelis Lilbok wrote:
> Maybe something like RLE compression? errrr.... sounds good. but no idea what it is! Could you expand on> that? Hugh
http://www.prepressure.com/techno/compressionrle.htm
I try to find a class writen by me, i used it befgore for something :)) Meelis Show quoteHide quote "Hugh Janus" <my-junk-acco***@hotmail.com> wrote in message news:1150717356.596406.70190@f6g2000cwb.googlegroups.com... > > Meelis Lilbok wrote: >> Maybe something like RLE compression? >> > > errrr.... sounds good. but no idea what it is! Could you expand on > that? > > > Hugh > Meelis Lilbok wrote:
> http://www.prepressure.com/techno/compressionrle.htm Thanks Meelis, I have a feeling that that is what the code in the link> > > I try to find a class writen by me, i used it befgore for something :)) > > > Meelis > i posted does, or so it looks to me. What do you think? Either ways, I would be interested in trying your class to see which one works better! Here, i found my class.
It works, when in your text are 4-255 repeated characters, if there are more chars then 255 repated, you must modify my code Works like this a) Searches repated charactes and counts them b) If character changes, saves control character, count of repated charaters(as byte) and character to result string Hope this helps a little bit ;) meelis Show quoteHide quote "Hugh Janus" <my-junk-acco***@hotmail.com> wrote in message [attached file: RLE.zip]news:1150717943.668265.195710@u72g2000cwu.googlegroups.com... > > Meelis Lilbok wrote: >> http://www.prepressure.com/techno/compressionrle.htm >> >> >> I try to find a class writen by me, i used it befgore for something :)) >> >> >> Meelis >> > > Thanks Meelis, I have a feeling that that is what the code in the link > i posted does, or so it looks to me. What do you think? Either ways, > I would be interested in trying your class to see which one works > better! > ooops sry, there was a bug in my first code
rle2.zip is correc one :) Meelis Show quoteHide quote "Meelis Lilbok" <meelis.lil***@deltmar.ee> wrote in message [attached file: RLE2.zip]news:ei1Txt5kGHA.4284@TK2MSFTNGP05.phx.gbl... > Here, i found my class. > > It works, when in your text are 4-255 repeated characters, if there are > more > chars then 255 repated, you must modify my code > > Works like this > > a) Searches repated charactes and counts them > b) If character changes, saves control character, count of repated > charaters(as byte) and character to result string > > > Hope this helps a little bit ;) > > > meelis > > > > > > "Hugh Janus" <my-junk-acco***@hotmail.com> wrote in message > news:1150717943.668265.195710@u72g2000cwu.googlegroups.com... >> >> Meelis Lilbok wrote: >>> http://www.prepressure.com/techno/compressionrle.htm >>> >>> >>> I try to find a class writen by me, i used it befgore for something :)) >>> >>> >>> Meelis >>> >> >> Thanks Meelis, I have a feeling that that is what the code in the link >> i posted does, or so it looks to me. What do you think? Either ways, >> I would be interested in trying your class to see which one works >> better! >> > > > Meelis Lilbok wrote:
Show quoteHide quote > Here, i found my class. Thanks! But your file is not attached. Could you paste the class file> > It works, when in your text are 4-255 repeated characters, if there are more > chars then 255 repated, you must modify my code > > Works like this > > a) Searches repated charactes and counts them > b) If character changes, saves control character, count of repated > charaters(as byte) and character to result string > > > Hope this helps a little bit ;) > here as text? Also, what if I do not know how many repeated characters there are in my string? You say that yours works for 4-255 repeated characters, but what if the number is unknown? Hugh Public Class clsCompress
Public Function CompressString(ByVal controlchar As String, ByVal text As String) As String Dim iPos As Integer, iLen As Integer, iCharCnt As Integer = 1, sChar As String Dim sResult As New System.Text.StringBuilder 'Get string length iLen = text.Length 'Get first char sChar = Left$(text, 1) 'Loop trough string For iPos = 2 To iLen 'If char has changed If sChar <> Mid$(text, iPos, 1) Then 'If CharCount is bigger then 3, add countrol char, count of chars as Chrw(count) and char If iCharCnt > 3 Then sResult.Append(controlchar & ChrW(iCharCnt) & sChar) iCharCnt = 1 Else 'Add just char sResult.Append(sChar, iCharCnt) iCharCnt = 1 End If Else 'Get next char sChar = Mid$(text, iPos, 1) iCharCnt = iCharCnt + 1 End If 'Get next char sChar = Mid$(text, iPos, 1) Next If iCharCnt > 3 Then sResult.Append(controlchar & ChrW(iCharCnt) & sChar) iCharCnt = 1 Else 'Add just char sResult.Append(sChar, iCharCnt) End If Return sResult.ToString End Function End Class Do you have to write this code? or would it be acceptable to use a free
third-party open source .net library? http://www.icsharpcode.com/OpenSource/SharpZipLib/Default.aspx I have used this library and whilst I can't give yuo any stats on speed or compression I can at least say that it hasn't ever crashed ;-) Meelis, your function works very well for me. Could you please post
the Uncompress function as well? This wersion works like this
lets say your string is abcdeeeeefg and control char is * after compressing abcd*?efg now when there are more then 255 e-chars, my function does not work anymore. then its must be modified to store length with 2 bytes Sry, englis is not my native language ;) Meelis Show quoteHide quote "Hugh Janus" <my-junk-acco***@hotmail.com> wrote in message news:1150720451.217298.323000@i40g2000cwc.googlegroups.com... > > Meelis Lilbok wrote: >> Here, i found my class. >> >> It works, when in your text are 4-255 repeated characters, if there are >> more >> chars then 255 repated, you must modify my code >> >> Works like this >> >> a) Searches repated charactes and counts them >> b) If character changes, saves control character, count of repated >> charaters(as byte) and character to result string >> >> >> Hope this helps a little bit ;) >> > > Thanks! But your file is not attached. Could you paste the class file > here as text? > > Also, what if I do not know how many repeated characters there are in > my string? You say that yours works for 4-255 repeated characters, but > what if the number is unknown? > > Hugh > Meelis Lilbok wrote:
> This wersion works like this Ahhh, now I understand perfectly! thanks for your help. I think i'll> > lets say your string is abcdeeeeefg and control char is * > > > after compressing abcd*?efg > > now when there are more then 255 e-chars, my function does not work anymore. > then its must be modified to store length with 2 bytes > > > Sry, englis is not my native language ;) > Meelis > need to modify the code because I don't know if i will find more than 255 characters repeated, it is very possible. Do you know what changes are required for your class to work with 2 bytes instead? One solution is to use 255 length blocks :)
if count is 255 then counting starts again from 1 Meelis "Hugh Janus" <my-junk-acco***@hotmail.com> wrote in message Meelis Lilbok wrote:news:1150721363.469704.60010@c74g2000cwc.googlegroups.com... Show quoteHide quote > This wersion works like this Ahhh, now I understand perfectly! thanks for your help. I think i'll> > lets say your string is abcdeeeeefg and control char is * > > > after compressing abcd*?efg > > now when there are more then 255 e-chars, my function does not work > anymore. > then its must be modified to store length with 2 bytes > > > Sry, englis is not my native language ;) > Meelis > need to modify the code because I don't know if i will find more than 255 characters repeated, it is very possible. Do you know what changes are required for your class to work with 2 bytes instead? p.s. all the other examples i find are for compressing files. I want
to compress a string in memory, send it and then discard.
Bug in VS 2005 VB "Application Framework"?
SQL Update - DataViewRow Help needed, Removing duplicate lines in text file How to prevent DISTILLER from propting output filename ? How do I get COMPLETE response from HttpWebResponse using StreamReader??? Saving PointF data in MSAccess Adding reference errors... Unknown error.... my.settings and the connectionstring My form has a hiccup |
|||||||||||||||||||||||