开发者

How do I output a literal sequence with NSLog

开发者 https://www.devze.com 2023-01-19 14:52 出处:网络
I want NSLogto output a literal escape sequence, without treating it as a pattern. Take, for example NSLog(@\"image%03d.jpg\");, who\'s out开发者_C百科put I want to be the actual contents, image%03d.

I want NSLogto output a literal escape sequence, without treating it as a pattern.

Take, for example NSLog(@"image%03d.jpg");, who's out开发者_C百科put I want to be the actual contents, image%03d.jpg instead of image000.jpg.

I've tried various escape sequences like NSLog(@"image\\%03d.jpg");, NSLog(@"image\\%03\\d.jpg"); and NSLog(@"image%03\\d.jpg");, none of which yielded the expected results.

The problem only grows further when I'm including an actual pattern that I do want to replace, after the literal one: NSLog(@"image\\%03d.jpg test %d", 1);, that I'd like to output image%03d.jpg test 1.


Use two %% characters and you will get the desired results:

NSLog(@"image%%03d.jpg");
0

精彩评论

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