开发者

(iPhone)URL formatting question

开发者 https://www.devze.com 2023-01-09 21:42 出处:网络
I am trying to format a URL but am getting a bug out of it. My code is below. NSString *twitterURL = [NSString stringWithFormat:@\"http://twitter.com/?status开发者_Go百科=My%20score%20is:%i%20and%20C

I am trying to format a URL but am getting a bug out of it. My code is below.

NSString *twitterURL = [NSString stringWithFormat:@"http://twitter.com/?status开发者_Go百科=My%20score%20is:%i%20and%20CharsPerMin%20is:%@", currentScore, charPerMin.text]; 

When calling the method it doesn't do a thing. I think the issue is with %20. %20 is being used to space each word in the URL.


You need to escape your % signs by doubling them:

NSString *twitterURL = [NSString stringWithFormat:@"http://twitter.com/?status=My%%20PracticeTyper%%20score%%20is:%i%%20and%%20CharsPerMin%%20is:%@", currentScore, charPerMin.text];
0

精彩评论

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