I want to when should we use NSString
and when should we use the NSMutableString
, because we can append the string in NSString also,so what is the effective use of NSMutableString
in Objective C programming?
Essentially, there is no difference between string and String (capital S) in C#. String (capital S) is a class in the . NET framework in the System namespace. The fully qualified name is System.
A static, plain-text Unicode string object which you use when you need reference semantics or other Foundation-specific behavior.
If you create an object using a method that begins with init, new, copy, or mutableCopy, then you own that object and are responsible for releasing it (or autoreleasing it) when you're done with it. If you create an object using any other method, that object is autoreleased, and you don't need to release it.
NSMutableString is the abstract base class for a cluster of classes representing strings whose contents can be changed. It inherits from NSString. It extends the interface it inherits from NSString by adding methods to change the string contents.
I expect MutableString will be slightly more efficient in terms of memory as you are indicating early on that the program may need memory dynamically. NSString is likely to be allocated a single, suitably sized block of memory.
With NSString and its stringBy...
methods, you are creating new objects, releasing the old one (if need be) and making the new object autorelease. (Take care if you are changing from non-autorelease to autorelease, you may have a release in your dealloc that isn't needed anymore)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With