\n 不会跳到 NSString 中的下一行
NSMutableString *a = @"Hi";
NSMutableString *b =[a stringByAppendingString:@"\n\n Hi Again"];
上面的代码没有给出错误,但没有在下一行添加“Hi Again”。为什么?
NSMutableString *a = @"Hi";
NSMutableString *b =[a stringByAppendingString:@"\n\n Hi Again"];
The above doesn't give an error but does not put "Hi Again" on the next line. Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
编辑2
我在发帖后意识到,OP 的标题中有 NSString,但在代码中放入了 NSMutableString。我已提交编辑以将 NSMutableString 更改为 NSString。
我会留下这个,因为它仍然可能有帮助。
嗯,我很惊讶它没有给出错误,因为你给了一个 NSMutableString 一个 NSString。
您需要阅读 NSMutableStrings。
给你一个主意
EDIT2
I realised after posting, that the OP had NSString in the title but put NSMutableString in the code. I have submitted an edit to change the NSMutableString to NSString.
I will leave this as it still maybe helpful.
Well I am surprised that does not give an error, because you are giving a NSMutableString a NSString.
You need to read the Documentation on NSMutableStrings.
to give you an idea
我认为这个 可能对你有帮助。你宁愿使用 '\r' 而不是 '\n'
我也遇到了类似的问题,发现 \n 在 LLDB 中有效,但在 GDB 中无效
I think this might help you. You'd rather to use '\r' instead of '\n'
I also had a similar problem and found \n works in LLDB but not in GDB
尝试使用 NSString。你可以使用:
Try using
NSString
. You could use:如果您的字符串位于 UIView(例如 UILabel)中,您还需要将行数设置为 0
If your string is going in a UIView (e.g a UILabel), you also need to set the number of lines to 0