views:

172

answers:

1

Hi !

I have been having some problem with the stringByAddingPercentEscapesUsingEncoding: method. Here's what happens:

When I try to use the method to convert the NSString:

"..City=Cl&PostalCode=Rh6 0Nt"

I get this this..

"City=Cl&PostalCode=Rh62t"

It should be:

"..City=Cl&PostalCode=Rh6%200Nt"

What can I do about this? Thanks in advance !!

+1  A: 

For me, this:

NSString *s=[@"..City=Cl&PostalCode=Rh6 0Nt" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"s=%@",s);

... outputs:

s=..City=Cl&PostalCode=Rh6%200Nt

You're most likely using the wrong encoding.

TechZen
Thanks for the reply.Yea, I realized a dumb mistake in my NSLog.. I had NSLog the string encoded string by NSLog(str) instead of NSLog(@"%@",str) and that had caused the incorrect output on my Console.Thanks!
Susanth
It's good idea to always post your logging code so others can see and catch these types of errors. Everyone makes them and for some reason they're hard to see if you're the one who wrote the code.
TechZen