Reputation: 3
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
Upvotes: 0
Views: 467
Reputation: 237030
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.
Upvotes: 1