objective-c连接NSString [英] objective-c concatenate NSString
本文介绍了objective-c连接NSString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在连接NSString时遇到问题。
I have problems to concatenate NSString.
每次按下按钮我都希望将某些内容(aux)添加到我的字符串(myString)中。所以:
Each time I pushed a button I want that something ("aux") is added to my string ("myString"). so:
NSString *aux = [NSString stringWithFormat: @"%d", buttonIndex];
myString=[NSString stringWithFormat:@"%@/%@",posTargetaText,aux];
aux = nil;
我第一次按下按钮时效果不错,但第二次不起作用。
The first time i pushed the button it works good but the second it doesn't work.
有些帮助吗?
推荐答案
所以你当然可以使用 stringWithFormat
,但为什么不使用 stringByAppendingString
,因为那正是你想要做的?
So you can certainly use stringWithFormat
, but why don't you use stringByAppendingString
instead, since that's exactly what you want to do?
NSString *newString = [firstString stringByAppendingString:secondString];
除非你有令人信服的理由,否则你真的不需要使用可变字符串。
You really don't need to use a mutable string unless you have a compelling reason to.
这篇关于objective-c连接NSString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文