Class: NSMutableString

Inherits:
NSString show all

Overview

The NSMutableString class declares the programmatic interface to an object that manages a mutable string—that is, a string whose contents can be edited—that conceptually represents an array of Unicode characters. 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.

Direct Known Subclasses

String

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSString

availableStringEncodings, #boolValue, #cStringUsingEncoding:, #canBeConvertedToEncoding:, #capitalizedString, #capitalizedStringWithLocale:, #caseInsensitiveCompare:, #characterAtIndex:, #commonPrefixWithString:options:, #compare:, #compare:options:, #compare:options:range:, #compare:options:range:locale:, #completePathIntoString:caseSensitive:matchesIntoArray:filterTypes:, #componentsSeparatedByCharactersInSet:, #componentsSeparatedByString:, #dataUsingEncoding:, #dataUsingEncoding:allowLossyConversion:, #decomposedStringWithCanonicalMapping, #decomposedStringWithCompatibilityMapping, defaultCStringEncoding, #description, #doubleValue, #encode, #encode!, #enumerateLinesUsingBlock:, #enumerateLinguisticTagsInRange:scheme:options:orthography:usingBlock:, #enumerateSubstringsInRange:options:usingBlock:, #fastestEncoding, #fileSystemRepresentation, #floatValue, #getBytes:maxLength:usedLength:encoding:options:range:remainingRange:, #getCString:maxLength:encoding:, #getCharacters:range:, #getFileSystemRepresentation:maxLength:, #getLineStart:end:contentsEnd:forRange:, localizedNameOfStringEncoding:, localizedStringWithFormat:, pathWithComponents:, string, stringWithCString:encoding:, stringWithCharacters:length:, stringWithContentsOfFile:encoding:error:, stringWithContentsOfFile:usedEncoding:error:, stringWithContentsOfURL:encoding:error:, stringWithContentsOfURL:usedEncoding:error:, stringWithFormat:, stringWithString:, stringWithUTF8String:

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Class Method Details

+ (Object) stringWithCapacity(capacity)

Returns an empty NSMutableString object with initial storage for a given number of characters. The number of characters indicated by capacity is simply a hint to increase the efficiency of data storage. The value does not limit the length of the string.

Parameters:

  • capacity (Integer)

    The number of characters the string is expected to initially contain.

Returns:

Instance Method Details

- (Object) appendFormat(format, ...)

Adds a constructed string to the receiver.

Parameters:

  • format

    A format string. See “Formatting String Objects” for more information. This value must not be nil.Important: Raises an NSInvalidArgumentException if format is nil.

  • ...

    A comma-separated list of arguments to substitute into format.

Returns:

- (Object) appendString(aString)

Adds to the end of the receiver the characters of a given string.

Parameters:

  • aString (String)

    The string to append to the receiver. aString must not be nil

Returns:

- (Object) deleteCharactersInRange(aRange)

Removes from the receiver the characters in a given range. This method treats the length of the string as a valid range value that returns an empty string.

Parameters:

  • aRange (NSRange)

    The range of characters to delete. aRange must not exceed the bounds of the receiver.Important: Raises an NSRangeException if any part of aRange lies beyond the end of the string.

Returns:

- (Object) initWithCapacity(capacity)

Returns an NSMutableString object initialized with initial storage for a given number of characters, The number of characters indicated by capacity is simply a hint to increase the efficiency of data storage. The value does not limit the length of the string.

Parameters:

  • capacity (Integer)

    The number of characters the string is expected to initially contain.

Returns:

  • (Object)

    An initialized NSMutableString object with initial storage for capacity characters. The returned object might be different than the original receiver.

- (Object) insertString(aString, atIndex:anIndex)

Inserts into the receiver the characters of a given string at a given location. The new characters begin at anIndex and the existing characters from anIndex to the end are shifted by the length of aString.This method treats the length of the string as a valid index value that returns an empty string.

Parameters:

  • aString (String)

    The string to insert into the receiver. aString must not be nil.

  • anIndex (Integer)

    The location at which aString is inserted. The location must not exceed the bounds of the receiver.Important: Raises an NSRangeException if anIndex lies beyond the end of the string.

Returns:

- (Object) replaceCharactersInRange(aRange, withString:aString)

Replaces the characters from aRange with those in aString. This method treats the length of the string as a valid range value that returns an empty string.

Parameters:

  • aRange (NSRange)

    The range of characters to replace. aRange must not exceed the bounds of the receiver.Important: Raises an NSRangeException if any part of aRange lies beyond the end of the receiver.

  • aString (String)

    The string with which to replace the characters in aRange. aString must not be nil.

Returns:

- (Integer) replaceOccurrencesOfString(target, withString:replacement, options:opts, range:searchRange)

Replaces all occurrences of a given string in a given range with another given string, returning the number of replacements. This method treats the length of the string as a valid range value that returns an empty string.

Parameters:

  • target (String)

    The string to replace.Important: Raises an NSInvalidArgumentException if target is nil.

  • replacement (String)

    The string with which to replace target.Important: Raises an NSInvalidArgumentException if replacement is nil.

  • opts (NSStringCompareOptions)

    A mask specifying search options. See String Programming Guide for details.If opts is NSBackwardsSearch, the search is done from the end of the range. If opts is NSAnchoredSearch, only anchored (but potentially multiple) instances are replaced. NSLiteralSearch and NSCaseInsensitiveSearch also apply.

  • searchRange (NSRange)

    The range of characters to replace. aRange must not exceed the bounds of the receiver. Specify searchRange as NSMakeRange(0, [receiver length]) to process the entire string.Important: Raises an NSRangeException if any part of searchRange lies beyond the end of the receiver.

Returns:

  • (Integer)

    The number of replacements made.

- (Object) setString(aString)

Replaces the characters of the receiver with those in a given string.

Parameters:

  • aString (String)

    The string with which to replace the receiver's content. aString must not be nil.

Returns: