Search code examples
iphonenslog

stringByAddingPercentEscapesUsingEncoding not working with NSStrings with ' 0'


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 !!


Solution

  • 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.