How do I output a literal sequence with NSLog
I want NSLog
to 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");
精彩评论