views:

73

answers:

1

If I call "[NSString stringWithFormat:@"Testing \n %@",variableString]"; I get what I would expect, which is Testing, followed by a new line, then the contents of variableString.

However, if i try NSString *testString = @"Testing \n %@"; //forgive shorthand here [NSString stringWithFormat,testString,variableString]

the output actually literally writes \n to the screen instead of a newline. any workaround to this? seems odd to me

+1  A: 

What you describe is not normally the case. The \n is translated into a newline by the compiler — the program will never see that you wrote it as \n.

However, if you're actually trying to use a string you've obtained from somewhere else (that is, you didn't really write it in your source file) that literally contains the character sequence "\n", yes, it will be printed literally. In that case you will need to replace the "\n" with a newline character yourself.

Chuck
a ha! it is coming from a plist file. interesting i thought it was a runtime thing not compile time. great info!
Jeff