(iPhone)URL格式问题

时间:2010-07-29 08:46:54

标签: iphone objective-c string formatting

我正在尝试格式化网址,但我发现了一个错误。我的代码如下。

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

调用方法时,它没有做任何事情。我认为问题出在%20上。 %20用于区分网址中的每个字词。

1 个答案:

答案 0 :(得分:3)

你需要通过加倍来逃避你的%标志:

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