NSString nslog revealing “\\n” newline character

2019-02-21 20:37发布

问题:

I want to log an NSString but when I log it, it doesn't show the new line character " n". How can I make it so it does? Thanks.

回答1:

You can process the string first and replace all occurrences of \n with \\n

NSString *newString = [originalString stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"];