O'Reilly logo

Programming in Objective-C, Sixth Edition by Stephen G. Kochan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mutable Strings

You can use the NSMutableString class to create string objects whose characters can be changed. Because this class is a subclass of NSString, you can use all of NSString’s methods as well.

When we speak of mutable versus immutable string objects, we are talking about changing the actual characters within the string. Either a mutable or an immutable string object can always be set to a completely different string object during execution of the program. This was stressed in the discussion of Program 15.4. So, for example, consider the following:

str1 = @"This is a string";   ...str1 = [str1 substringFromIndex: 5];

In this case, str1 is first set to a constant character string object. Later in the program, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required