0
Is there is a way to reduce the length of a string
using String encoding algorithm.

Unfortunately "Huffman coding" is not a solution for my case. I am searching for a coding algorithm which takes a string and generate a string which is shorter than the original string(input).

3
  • You can base64 encode the data produced by Huffman coding. Not sure whether it is shorter, but it will produce a printable string. Commented Jun 18, 2012 at 4:33
  • What is your string??? Did you mean to compress? Commented Jun 18, 2012 at 4:34
  • @Manjoor Yes i need some kind of compress Commented Jun 18, 2012 at 4:42

3 Answers 3

2

There is no way to shorten an arbitrary string, just as there is no general compression method that works in all cases. So what you need to do is pick a compression method that apples to your expected inputs and use that. Then you just need to convert the results back to a string.

In case you were merely wondering how to convert the results back to a string, there are again any number of ways. Base64 is easy and works well enough. However, it has a 25% overhead compared to a pure binary encoded string.

Sign up to request clarification or add additional context in comments.

2 Comments

Actually, I believe Base64 has ~33% overhead.
Sorry, you're right. The overhead is 33% of the original string and 25% of the encoded string.
2

Hopefully this answers your intended question. There is a library, smaz which compresses short English strings efficiently. Perhaps luckily for you, it actually encodes the string. If your strings aren't English, the general method used by smaz (a static dictionary) can be used with other compressors.

2 Comments

Thank you for the information. This library may be suitable for my case. But the implementation is in C. I am searching for a Java and/or c# implementation.
@KeshanDeSilva It's a very small program, you should be able to convert it by hand pretty easily. Good luck!
0

See "English Text compression test". In the article you will find almost all possible algorithms to compress an english text. May be some of them could satisfy your requirements.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.