Results 1 to 6 of 6

Thread: Compressing a string ("this is my string" -> "aspfoi") (semi urgent)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    Gainesville, FL
    Posts
    131

    Exclamation

    Hello!

    I need a string compression algorithm, and I can't find one anywhere.

    Actually, I found this one:
    http://www.planetsourcecode.com/vb/s...&txtCodeId=467

    But it doesn't work (the dictionary is the wrong size).
    Plus, I'm looking for a little bit stronger compression if possible (but not neccesary).

    I also found this one:
    http://www.planetsourcecode.com/vb/s...txtCodeId=2075

    But, it does not work for me, because I need to compress/encrypt strings like:
    "Hey everyone, my name is Marcus. How is everyone?"
    and that last one makes my string even longer.

    (It's for a chat program, client/server). Help?
    (If anyone could get the first one working, that might be good!)

    Thanks!

  2. #2
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Raydr,

    Not a problem to fix that code.

    Code:
    'change the following
    If Len(Dict$) <> 320 Then 'just To check...
                MsgBox "PACKING ERROR: Dictionary is the wrong size"
                Exit Function
            End If
    
    'to this
    'He seems to have got the length of his own string wrong.
    If Len(Dict$) <> 312 Then 'just To check...
                MsgBox "PACKING ERROR: Dictionary is the wrong size"
                Exit Function
            End If
    Iain, thats with an i by the way!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    Gainesville, FL
    Posts
    131
    I probably looked like a dummy.
    I'm not familiar with compression/encryption routines, so I'm iffy about modifying them. However, I did apply your change, and found OTHER bugs in this code.

    I wonder if this code was even tested before it was put out there? It stops when it encounters a space also.

    Perhaps someone could point me to a better compression function??

  4. #4
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    You are right, that code has been badly tested. I have changed it so it works. Any more problems let me know.

    Seeing as i would be breaching copyright, i can't post it here. Change the following.

    Code:
    If cnt = Len(text$) Then'if the End of the String has been reached
                            text$ = Chr$(255) + temp$ + Chr$(Asc(Mid$(text$, cnt, 1)) - 32)
                            Exit Function '^^^^ add the last character
                        End If
    
    
    
    'change it to this.  The guy had forgot to return the value.
    If cnt = Len(text$) Then 'if the End of the String has been reached
                            text$ = Chr$(255) + temp$ + Chr$(Asc(Mid$(text$, cnt, 1)) - 32)
                            PackTxt = text$
                            Exit Function '^^^^ add the last character
                        End If
    Iain, thats with an i by the way!

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    Gainesville, FL
    Posts
    131
    I had already fixed that part.
    But try compressing and uncompressing this:

    "This is a test"
    "My name is Marcus".

    I think you'll see what the problem is.

    I think I just want a new function.

  6. #6
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Not a problem. Those strings work fine.

    This is my guess at why it is not working for you.

    You are using TextBoxes to hold the strings, aren't you? If so, this is why it does not work. The textbox will not display an awful lot of the ascii character set.

    If you use string variables to hold the strgins, you should not have a problem.
    Iain, thats with an i by the way!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width