Important: The information in this document is obsolete and should not be used for new development.
Inherits from | |
Package | com.apple.cocoa.foundation |
Companion guide |
The NSMutableStringReference 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 NSStringReference class.
An immutable string is implemented as an array of Unicode characters (in other words, as a text string). The NSMutableStringReference class adds one primitive method—replaceCharactersInRange
—to the basic string-handling behavior inherited from NSStringReference. All other methods that modify a string work through this method. For example, insertStringAtIndex
simply replaces the characters in a range of 0 length, while deleteCharactersInRange
replaces the characters in a given range with no characters.
The Application Kit also uses NSParagraphStyle and its subclass NSMutableParagraphStyle to encapsulate the paragraph or ruler attributes used by the NSAttributedString classes.
appendString
deleteCharactersInRange
insertStringAtIndex
replaceCharactersInRange
replaceOccurrencesOfString
setString
Creates an empty NSMutableStringReference.
public NSMutableStringReference
()
Creates a new NSMutableStringReference by converting the bytes in aData into Unicode characters.
public NSMutableStringReference
(NSData aData, int encoding)
aData must be an NSData object containing bytes in encoding and the default plain text format (that is, pure content with no attributes or other markups) for that encoding.
Creates a new NSMutableStringReference by reading characters from the location named by aURL.
public NSMutableStringReference
(java.net.URL aURL)
If the contents begin with a byte-order mark (U+FEFF or U+FFFE), interprets the contents as Unicode characters; otherwise interprets the contents as characters in the default C-string encoding. Returns null
if the location can’t be opened.
Creates a new NSMutableStringReference by converting the bytes at aURL into Unicode characters.
public NSMutableStringReference
(java.net.URL aURL, int encoding)
aURL must contain bytes in encoding and the default plain text format (that is, pure content with no attributes or other markups) for that encoding.
Adds the characters of aString to the end of the receiver.
public void appendString
(String aString)
aString may not be null
.
Adds the characters of aStringReference to the end of the receiver.
public void appendString
(NSStringReference aStringReference)
aStringReference may not be null
.
Removes the characters in aRange from the receiver.
public void deleteCharactersInRange
(NSRange aRange)
Throws a RangeException
if any part of aRange lies beyond the end of the string. This method treats the length of the string as a valid range value that returns an empty string.
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.
public void insertStringAtIndex
(String aString, int anIndex)
aString may not be null
. Throws a RangeException
if anIndex lies beyond the end of the string. This method treats the length of the string as a valid index value that returns an empty string.
Inserts the characters of aStringReference 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 aStringReference.
public void insertStringAtIndex
(NSStringReference aStringReference, int anIndex)
aStringReference may not be null
. Throws a RangeException
if anIndex lies beyond the end of the string.
Replaces the characters from aRange with those in aString.
public void replaceCharactersInRange
(NSRange aRange, String aString)
aString may not be null
. Throws a RangeException
if any part of aRange lies beyond the end of the receiver. This method treats the length of the string as a valid range value that returns an empty string.
Replaces the characters from aRange with those in aStringReference.
public void replaceCharactersInRange
(NSRange aRange, NSStringReference aStringReference)
aStringReference may not be null
. Throws a RangeException
if any part of aRange lies beyond the end of the receiver. This method treats the length of the string as a valid range value that returns an empty string.
This method replaces all occurrences of target with replacement, in the specified searchRange of the receiver.
public void replaceOccurrencesOfString
(String target, String replacement, int opts, NSRange searchRange)
Throws an InvalidArgumentException
if any of the arguments are null
. Throws a RangeException
if any part of searchRange lies beyond the end of the receiver. This method treats the length of the string as a valid range value that returns an empty string. If opts is BackwardsSearch
, the search is done from the end of the range. If opts is AnchoredSearch
, only anchored (but potentially multiple) instances are replaced. LiteralSearch
and CaseInsensitiveSearch
also apply. Specify searchRange as new NSRange(0, receiver.length())
to process the entire string.
Replaces the characters of the receiver with those in aString.
public void setString
(String aString)
aString may not be null
.
Replaces the characters of the receiver with those in aStringReference.
public void setString
(NSStringReference aStringReference)
aStringReference may not be null
.
© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)