如何使用NSMutableString附加NSMutableString? [英] How to append a NSMutableString with a NSMutableString?

查看:79
本文介绍了如何使用NSMutableString附加NSMutableString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSMutableString *str, *str1;

//在这里分配

我是使用
[str appendString:str1] 无效。
[str appendFormat:str1] 无效。

i am using [str appendString:str1] is not working. [str appendFormat:str1] is not working.

那么,如何追加 NSMutableString 另一个 NSMutableString

So, how to append a NSMutableString with another NSMutableString.

@str 是一个空字符串初始化为 nil str1 有一些价值。 [str appendString str1] 返回 null

@str is an empty string initialize to nil. str1 has some value. [str appendString str1] returns null

推荐答案

好像你正在向 nil 发送消息。 nil NOT 一个对象,它只是 nothing 。向 nothing 发送消息只返回 nothing 。为了附加这些字符串,您需要初始化为空字符串。像这样:

Seems like your're sending a message to nil. nil is NOT an object, it's just nothing. Sending a message to nothing just return nothing. In order to append these strings, you need to initialize to an empty string. Like so:

NSMutableString *str = [NSMutableString string];

然后你的代码就可以了。像这样:

Then your code will work. Like so:

[str appendString:str1];

这篇关于如何使用NSMutableString附加NSMutableString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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