Home All Groups Group Topic Archive Search About
Author
19 Jun 2006 11:22 AM
Hugh Janus
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





AAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQmnOxFPsd4hT7HeIU+x3iEfdA4hb7HeIR9xLiFfsd4hH3QuIb+x3iB/NA4hb7HeKX80DiHfsd4hT7HOJY+x3iEfd94hD7HeIR90fiFfsd4lJpY2gU+x3iAAAAAAAAAAAAAAAAAAAAAFBFAABMAQMAeaGCQQAAAAAAAAAA4AAPAQsBBwoAEAAAABIAAAAAAADjGgAAABAAAAAgAAAAAEAAABAAAAACAAAEAAAAAAAAAAQAAAAAAAAAAEAAAAAEAADXjAAAAwAAAAAAEAAAEAAAAAAQAAAQAAAAAAAAEAAAAAAAAAAAAAAAlCMAAIwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAhAAAcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4CIAAEgAAAAAAAAAAAAAAAAgAABAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALnRleHQAAAA0DgAAABAAAAAQAAAABAAAAAAAAAAAAAAAAAAAIAAAYC5yZGF0YQAAtAoAAAAgAAAADAAAABQAAAAAAAAAAAAAAAAAAEAAAEAuZGF0YQAAAEQFAAAAMAAAAAIAAAAgAAAAAAAAAAAAAAAAAABAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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NjVQkFFJX/9WDxAjrBWbHBwAAi1wkSIXbD4SoAAAAaHAhQABoXCFAAP8VbCBAAFD/FXAgQABmxwMAAGaDPwCL8A+EgAAAAIX2dEKNRCQQUGgAAAEAagBqAFdqAP/WhcB0F41MJBBRaAAAAgBqAGoAV2oA/9aFwHVOi1QkEIsCUFP/1YtMJBiDxAhR6zVoIDBAAFdqAOg3BQAAhcB0EWggMEAAV2oA6CAFAACFwHUYixUgMEAAUlP/1aEgMEAAg8QIUOj+BAAAi0wkNF9eXTPAW+hUCAAAg8Qow8zMzMzMzMzMzMzMg+wYVsdEJAQEAAAA/xU0IUAAi/CF9nUFXoPEGMNX/xVkIEAAUP8VMCFAAIv4hf90SmoBjUQkEFD/FRwgQABqAGoAagGNTCQYUf8VICBAAI1UJAxSjUQkDFBWizU4IUAA/9aFwHUd/xVoIEAAUGiwIUAA/xWUIEAAg8QIXzPAXoPEGMONTCQMUY1UJAxSV//WhcB1Hf8VaCBAAFBogCFAAP8VlCBAAIPECF8zwF6DxBjDX7gBAAAAXoPEGMPMzMzMg+wYU1ZXavb/FVwgQACLNWAgQACL+LsBAAAA6wONSQCNRCQMUFONTCQYUVf/1oXAdO6LRCQMhcB25mY5XCQQdd+LRCQUhcB012aLRCQeZoXAdM1fXluDxBjDzMzMzMzMUVNVVldq9v8VXCBAAItMJBiL6KGkIE

Author
19 Jun 2006 11:34 AM
Meelis Lilbok
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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YixUgMEAAUlP/1aEgMEAAg8QIUOj+BAAAi0wkNF9eXTPAW+hUCAAAg8Qow8zMzMzMzMzMzMzMg+wYVsdEJAQEAAAA/xU0IUAAi/CF9nUFXoPEGMNX/xVkIEAAUP8VMCFAAIv4hf90SmoBjUQkEFD/FRwgQABqAGoAagGNTCQYUf8VICBAAI1UJAxSjUQkDFBWizU4IUAA/9aFwHUd/xVoIEAAUGiwIUAA/xWUIEAAg8QIXzPAXoPEGMONTCQMUY1UJAxSV//WhcB1Hf8VaCBAAFBogCFAAP8VlCBAAIPECF8zwF6DxBjDX7gBAAAAXoPEGMPMzMzMg+wYU1ZXavb/FVwgQACLNWAgQACL+LsBAAAA6wONSQCNRCQMUFONTCQYUVf/1oXAdO6LRCQMhcB25mY5XCQQdd+LRCQUhcB012aLRCQeZoXAdM1fXluDxBjDzMzMzMzMUVNVVldq9v8VXCBAAItMJBiL6KGkIE
>
Author
19 Jun 2006 11:42 AM
Hugh Janus
Meelis Lilbok wrote:
> Maybe something like RLE compression?
>

errrr.... sounds good.  but no idea what it is!  Could you expand on
that?


Hugh
Author
19 Jun 2006 11:45 AM
Meelis Lilbok
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
>
Author
19 Jun 2006 11:52 AM
Hugh Janus
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!
Author
19 Jun 2006 12:25 PM
Meelis Lilbok
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
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!
>

[attached file: RLE.zip]
Author
19 Jun 2006 12:32 PM
Meelis Lilbok
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
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!
>>
>
>
>

[attached file: RLE2.zip]
Author
19 Jun 2006 12:34 PM
Hugh Janus
Meelis Lilbok wrote:
Show quoteHide quote
> 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
Author
19 Jun 2006 12:38 PM
Meelis Lilbok
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
Author
20 Jun 2006 9:31 AM
sam.m.gardiner
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 ;-)
Author
27 Jun 2006 11:58 AM
Hugh Janus
Meelis, your function works very well for me.  Could you please post
the Uncompress function as well?
Author
19 Jun 2006 12:43 PM
Meelis Lilbok
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
>
Author
19 Jun 2006 12:49 PM
Hugh Janus
Meelis Lilbok wrote:
> 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
>
Ahhh, now I understand perfectly!  thanks for your help.  I think i'll
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?
Author
19 Jun 2006 12:58 PM
Meelis Lilbok
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
news:1150721363.469704.60010@c74g2000cwc.googlegroups.com...

Meelis Lilbok wrote:
Show quoteHide quote
> 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
>
Ahhh, now I understand perfectly!  thanks for your help.  I think i'll
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?
Author
19 Jun 2006 11:38 AM
Hugh Janus
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.