PATH  Documentation > Mac OS X > Foundation Reference: Objective-C



Table of Contents

NSMutableString


Inherits from:
NSString : NSObject
Conforms to:
NSCoding
(NSString)
NSCopying (NSString)
NSMutableCopying (NSString)
NSObject (NSObject)
Declared in:
Foundation/NSString.h




Class Description


The NSMutableString class declares the programmatic interface to an object that manages a mutable string-that is, a string whose contents can be edited. To construct and manage an immutable string-or a string that cannot be changed after it has been created-use an object of the NSString class.

An immutable string is implemented as array of Unicode characters (in other words, as a text string). The NSMutableString class adds one primitive method- replaceCharactersInRange:withString:-to the basic string-handling behavior inherited from NSString. All other methods that modify a string work through this method. For example, insertString:atIndex: simply replaces the characters in a range of zero length, while deleteCharactersInRange: replaces the characters in a given range with no characters.




Method Types


Creating temporary strings
+ stringWithCapacity:
Initializing an NSMutableString
- initWithCapacity:
Modifying a string
- appendFormat:
- appendString:
- deleteCharactersInRange:
- insertString:atIndex:
- replaceCharactersInRange:withString:
- setString:


Class Methods



stringWithCapacity:

+ (id)stringWithCapacity:(unsigned)capacity

Returns an empty mutable string, using capacity as a hint for how much initial storage to reserve.


Instance Methods



appendFormat:

- (void)appendFormat:(NSString *)format, ...

Adds a constructed string to the receiver. Creates the new string using NSString's stringWithFormat: method with the arguments listed.

See Also: - appendString:



appendString:

- (void)appendString:(NSString *)aString

Adds the characters of aString to the end of the receiver.

See Also: - appendFormat:



deleteCharactersInRange:

- (void)deleteCharactersInRange:(NSRange)aRange

Removes the characters in aRange from the receiver. Raises an NSRangeException if any part of aRange lies beyond the end of the string.

initWithCapacity:

- (id)initWithCapacity:(unsigned)capacity

Initializes a newly allocated NSMutableString, using capacity as a hint for how much memory to allocate. Returns self.

insertString:atIndex:

- (void)insertString:(NSString *)aString atIndex:(unsigned)loc

Inserts the characters of aString into the receiver, so the new characters begin at anIndex and the existing characters from anIndex to the end are shifted by the length of aString. Raises an NSRangeException if anIndex lies beyond the end of the string.

replaceCharactersInRange:withString:

- (void)replaceCharactersInRange:(NSRange)aRange withString:(NSString *)aString

Replaces the characters from aRange with those in aString. Raises an NSRangeException if any part of aRange lies beyond the end of the string.

setString:

- (void)setString:(NSString *)aString

Replaces the characters of the receiver with those in aString.


Table of Contents