Add Text To End of NSString

Discussion in 'Mac Programming' started by Blakeasd, May 4, 2011.

  1. macrumors 6502a

    Joined:
    Dec 29, 2009
    #1
    How to I add text to the end of an NSString?
    Thanks
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    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
     
  3. macrumors 604

    GFLPraxis

    Joined:
    Mar 17, 2004
    #3
    Create a new NSString with the new one added (either through stringByAppendingString or @"%@ blah blah",oldstring).

    Or use NSMutableStrings.
     

Share This Page