1

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

Take, for example NSLog(@"image%03d.jpg");, who's output 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.

luvieere
  • 37,065
  • 18
  • 127
  • 179

1 Answers1

7

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

NSLog(@"image%%03d.jpg");
Jacob Relkin
  • 161,348
  • 33
  • 346
  • 320