开发者

iOS4 - problem urlencoding a string

开发者 https://www.devze.com 2023-04-04 07:28 出处:网络
I\'m having a problem when trying to urlencode a string containing an ampersand.I\'m using the following code:

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 *sta开发者_开发问答dium = [[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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号