Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between NSString and NSMutableString? [duplicate]

Tags:

objective-c

I need a clarification regarding the difference between the NSString and NSMutableString. Can any one expand briefly?

like image 875
sekhar Avatar asked Oct 09 '10 06:10

sekhar


1 Answers

The difference between NSMutableString and NSString is that

NSMutableString: NSMutableString objects provide methods to modify the underlying array of characters they represent, while NSString does not. For example, NSMutableString exposes methods such as appendString, deleteCharactersInRange, insertString, replaceOccurencesWithString, etc. All these methods operate on the string as it exists in memory.

NSString: on the other hand only is a create-once-then-read-only string if you will; you'll find that all of its "manipulation" methods (substring, uppercaseString, etc) return other NSString objects and never actually modify the existing string in memory.

like image 62
Furqi Avatar answered Oct 26 '22 23:10

Furqi