macos NSString nslog 显示“\n”换行符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6052073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:04:03  来源:igfitidea点击:

NSString nslog revealing "\n" newline character

objective-ccocoamacosnsstringnewline

提问by user635064

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.

我想记录一个 NSString,但是当我记录它时,它没有显示换行符“n”。我怎样才能做到这一点?谢谢。

回答by jjwchoy

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

你可以先处理字符串和替换所有出现的\n\\n

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