new method to compress a string