开发者

NSString stringWithFormat adding a newline by itself

Why does this:

NSString *url =开发者_运维知识库 [NSString stringWithFormat:@"http://www.example.com/profile/%@/?s_iphone=true", author];
NSLog(@"url: %@", url);

Output this:

http://www.example.com/profile/AuthorName
            /?s_iphone=true

Needless to say the url won't load b/c there is a newline added to the string by itself. I've tried removing whitesapces/newlines and still had the same output. Its driving me crazy.

Matt


Try this -

NSString *url = [NSString stringWithFormat:@"http://www.example.com/profile/%@/?s_iphone=true", [author stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
NSLog(@"url: %@", url);

It will fix any new line characters at the beginning and end of your author string.


Author definitely has a new line in it. Try this:

NSLog(@"The author is %@ on a new line?", author);

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜