-2

how can i compress string in i phone

like "AmfkF04njgfdlnre4wp[fnv4s/sif03jgndlkrjrtyuiocvbnjm78dcfghjk89tgb dfgyhuic89vbnyhncvghj8ujmokjnfgbijk98nfgh0978njvcg9h08065yejktgb45ncvghyuitg45hnmpokjnb65yhjcvgf4354g3hjok/mnbcfghjkuh45jcfgh45dfv23bn" (200 charecters)

to Shorter for Send with SMS

assume 1 SMS can be sent only 170 characters if i send the text it need to send 2 SMS i want to send just only 1 SMS by compress the text to fit in 1 SMS.

i just want the string shorter to make it easy to sent ,it may be unreadable after compress. but need to be the same after decompress.

i try to read this but it not help me any thing.

thank you.

Community
  • 1
  • 1
MAXZZXAM
  • 137
  • 1
  • 4
  • 17

1 Answers1

2

If you want jfghirehgirl to mean Hello world 5555 hello world google, then you could just use a hash or dictionary:

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: @"Hello world 5555 hello world google", @"jfghirehgirl", nil];

Then, looking up jfghirehgirl will give you the original longer string.

A classic substitution based compression.

If you want an algorithmic transformation, gzip is about the best easily accessible general purpose compression algorithm. It also happens to be supported "on the wire" by most common protocols. Given the lack of context, hard to say more.


OK -- finally -- a concrete question:

like "AmfkF04njgfdlnre4wp[fnv4s/sif03jgndlkrjrtyuiocvbnjm78dcfghjk89tgb dfgyhuic89vbnyhncvghj8ujmokjnfgbijk98nfgh0978njvcg9h08065yejktgb45ncvghyuitg45hnmpokjnb65yhjcvgf4354g3hjok/mnbcfghjkuh45jcfgh45dfv23bn" (200 charecters)

That looks an awful lot like you banged on the keyboard. I.e. there is no signal there; it is white noise. White noise, by its very nature, does not compress.

Sure enough, copying that and doing this in terminal:

pbpaste | gzip --best -f | wc -c
121

Yields 121 characters. You might think 200 -> 121 is decent compression. It isn't; that is just the bits of the characters compressing. Since SMS has a limited character set, the result can't be used anyway. So, you'd need to encode it back to ASCII using something like base64.

I.e:

pbpaste > /tmp/foo
python
>>> x = file('/tmp/foo','r').read()
>>> len(x)
121
>>> y = b64encode(x)
>>> len(y)
164

164 characters. Not bad; maybe even usable (barring for the moment that you can neither read nor compose SMS messages programmatically on the iPhone, but the user could copy/paste).

So -- gzip, then base64 encode is the concrete answer given the contrived signal. A better answer could be given if the signal were more like the real signal you are going to send.

bbum
  • 162,346
  • 23
  • 271
  • 359
  • i want jfghirehgirl to mean Hello world 5555 hello world google and i can send jfghirehgirl to other device and they can decompress jfghirehgirl to mean Hello world 5555 hello world google – MAXZZXAM Apr 18 '11 at 03:03
  • That didn't actually clarify anything; you can do exactly that with a dictionary shared on both sides *or* by using a compression algorithm like gzip. Do you mean "arbitrary input sent over the wire"? – bbum Apr 18 '11 at 04:35
  • yes the compress text "jfghirehgirl" can be sent via sms or email and reciver can be decompress it to "Hello world 5555 hello world google" by use only compressed text. – MAXZZXAM Apr 19 '11 at 02:50
  • Example. i want to send text message 200 characters but a SMS message can contain only 170 character. if i send 200 character i will have to send 2 sms 170 first and 30 second. i don't want to send 2 SMS for 200 i want to send only a SMS by compress 200 characters to shorter than 170 characters – MAXZZXAM Apr 20 '11 at 02:10
  • Is it an arbitrary 200 characters or a fixed vocabulary of a limited # of 200 character sequences? i.e. are we talking random english phrases or something akin to a programming language w/fixed vocabulary, fixed sequence? (Ignoring, for the moment, the notion of using SMS as a transport layer for random data) – bbum Apr 20 '11 at 04:41
  • the text is limit to 200 characters generate by random ACSII character – MAXZZXAM Apr 20 '11 at 09:48
  • gzip it is, then. If it is truly random, the compression is likely to be minimal if any (try compressing an encrypted file). As well, you'll have to deal with whatever encoding limitations there are in SMS; i.e. you can't just gzip compress and send the resulting data. Of course, if your input is truly random, then what is the point of sending it over the wire? Without seeing some example strings (edit your question), it is impossible to say more. – bbum Apr 20 '11 at 23:23