在NSString中附加换行符 [英] Append a newline to an NSString

查看:258
本文介绍了在NSString中附加换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个:

if (soapResults != nil) {
    soapResults = [soapResults stringByAppendingString:@"\n"];
    }

但我收到警告:

在构建时从不同的Objective-C类型分配。

Assignment from distinct Objective-C type on build.

当我在设备上运行时,我得到:

When I run it on device I get:

Program received signal: "EXC_BAD_ACCESS".

来自gdb。

任何想法如何在没有收到警告或错误的情况下将换行符附加到NSString?

Any ideas how to append a newline to an NSString without getting a warning or error?

任何帮助赞赏//:)

推荐答案

另一种选择是: [NSString stringWithFormat:@%@ \ n,soapResults] 即使逻辑是相同的!

An alternative is: [NSString stringWithFormat: @"%@\n", soapResults] even if the logic is the same!

但是,即使在stringByAppendingString的情况下,它也会返回一个新字符串,但它不会更改目标,因此您必须将新字符串分配给新字符串NSString类的实例。

However, even in the case of stringByAppendingString, it returns a new string but it doesn't change the target, so you have to assign the new string to a new instance of the class NSString.

这篇关于在NSString中附加换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆