objective-c concatenate NSString
I have problems to concatenate NSString.
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 b开发者_StackOverflow中文版ut the second it doesn't work.
Some help please?
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.
Not sure what exactly you want to do. But as per your code aux will have new buttonIndex value each time and You will have always new mystring when ever you tap button.
If you want to append string always in myString that you need to do like this.
myString=[NSString stringWithFormat:@"%@%@/%@",myString,posTargetaText,aux];
You suppose to add previous value of myString as well in new myString string ?
Not sure this is what you want or something different. Please explain in detail if this is not.
If you wanna concatenate two strings use NSMutablestring and method appendstring instead of NSString.
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableString_Class/Reference/Reference.html
You need to use NSMutableString.
精彩评论