PDA

View Full Version : Add Text To End of NSString




Blakeasd
May 4, 2011, 04:29 PM
How to I add text to the end of an NSString?
Thanks



lee1210
May 4, 2011, 04:49 PM
How to I add text to the end of an NSString?
Thanks

You don't, NSString is immutable.

there is stringByAppendingString: which will return a new, autoreleased NSString with the current value plus the NSString passed in, but if you need to be altering a string "in place" you need NSMutableString. It has an appendString: method.

-Lee

GFLPraxis
May 4, 2011, 04:53 PM
How to I add text to the end of an NSString?
Thanks

Create a new NSString with the new one added (either through stringByAppendingString or @"%@ blah blah",oldstring).

Or use NSMutableStrings.