0

I'm having a problem when trying to urlencode a string containing an ampersand. I'm using the following code:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *stadium = [[prefs stringForKey:@"stadiumname"] 
           stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];

Now, the original string going in is "Brighton & Hove", which is correct when I drop it into NSLog before it gets encoded. After it's encoded, NSLog shows that it says "Brighton22ove", which is obviously failing when I pass it as a querystring.

Any suggestions?

Dave
  • 493
  • 9
  • 22
  • I think I might have found the answer here actually: http://stackoverflow.com/questions/705448/iphone-sdk-problem-with-ampersand-in-the-url-string but if anyone has any alternatives I'd be glad to hear them... – Dave Sep 09 '11 at 15:13
  • Doesn't seem as if that code is going to work, still getting odd results. – Dave Sep 09 '11 at 15:29
  • I've actually found the answer now at: http://cybersam.com/programming/proper-url-percent-encoding-in-ios All the code and examples are on that page. – Dave Sep 09 '11 at 15:39

1 Answers1

0

I've actually found the answer now at: cybersam.com/programming/proper-url-percent-encoding-in-ios All the code and examples are on that page

Dave
  • 493
  • 9
  • 22