views:

48

answers:

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.

+7  A: 

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

NSLog(@"image%%03d.jpg");
Jacob Relkin
luvieere
@luvieere You're welcome!
Jacob Relkin
@luvieere I didn't get the accepted answer yet, maybe you forgot?
Jacob Relkin
There was a time span that I couldn't award the accepted answer for - a several minutes system limit. No worries, ticked it now ;)
luvieere
@luvieere Thanks again!
Jacob Relkin