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, it is set to a substring. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access