Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/Foundation.framework |
Availability | Available in Mac OS X v10.0 and later. |
Companion guide | |
Declared in | NSCharacterSet.h |
Related sample code |
The NSMutableCharacterSet
class declares the programmatic interface to objects that manage a modifiable set of Unicode characters. You can add or remove characters from a mutable character set as numeric values in NSRange
structures or as character values in strings, combine character sets by union or intersection, and invert a character set.
Mutable character sets are less efficient to use than immutable character sets. If you don’t need to change a character set after creating it, create an immutable copy with copy
and use that.
NSMutableCharacterSet
defines no primitive methods. Subclasses must implement all methods declared by this class in addition to the primitives of NSCharacterSet
. They must also implement mutableCopyWithZone:
.
– addCharactersInRange:
– removeCharactersInRange:
– addCharactersInString:
– removeCharactersInString:
Adds to the receiver the characters whose Unicode values are in a given range.
- (void)addCharactersInRange:(NSRange)aRange
The range of characters to add.
aRange.location
is the value of the first character to add; aRange.location +
aRange.length– 1
is the value of the last. If aRange.length
is 0
, this method has no effect.
This code excerpt adds to a character set the lowercase English alphabetic characters:
NSMutableCharacterSet *aCharacterSet = [[NSMutableCharacterSet alloc] init]; |
NSRange lcEnglishRange; |
lcEnglishRange.location = (unsigned int)'a'; |
lcEnglishRange.length = 26; |
[aCharacterSet addCharactersInRange:lcEnglishRange]; |
NSCharacterSet.h
Adds to the receiver the characters in a given string.
- (void)addCharactersInString:(NSString *)aString
The characters to add to the receiver.
This method has no effect if aString is empty.
NSCharacterSet.h
Modifies the receiver so it contains only characters that exist in both the receiver and otherSet.
- (void)formIntersectionWithCharacterSet:(NSCharacterSet *)otherSet
The character set with which to perform the intersection.
NSCharacterSet.h
Modifies the receiver so it contains all characters that exist in either the receiver or otherSet.
- (void)formUnionWithCharacterSet:(NSCharacterSet *)otherSet
NSCharacterSet.h
Replaces all the characters in the receiver with all the characters it didn’t previously contain.
- (void)invert
Inverting a mutable character set, whether by invert
or by invertedSet
, is much less efficient than inverting an immutable character set with invertedSet
.
– invertedSet
(NSCharacterSet)NSCharacterSet.h
Removes from the receiver the characters whose Unicode values are in a given range.
- (void)removeCharactersInRange:(NSRange)aRange
The range of characters to remove.
aRange.location
is the value of the first character to remove; aRange.location +
aRange.length– 1
is the value of the last. If aRange.length
is 0
, this method has no effect.
NSCharacterSet.h
Removes from the receiver the characters in a given string.
- (void)removeCharactersInString:(NSString *)aString
The characters to remove from the receiver.
This method has no effect if aString is empty.
NSCharacterSet.h
© 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-05-23)