Next Page > Hide TOC

NSMutableCharacterSet Class Reference

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

Overview

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:.

Tasks

Adding and Removing Characters

Combining Character Sets

Inverting a Character Set

Instance Methods

addCharactersInRange:

Adds to the receiver the characters whose Unicode values are in a given range.

- (void)addCharactersInRange:(NSRange)aRange

Parameters
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.

Discussion

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];
Availability
See Also
Declared In
NSCharacterSet.h

addCharactersInString:

Adds to the receiver the characters in a given string.

- (void)addCharactersInString:(NSString *)aString

Parameters
aString

The characters to add to the receiver.

Discussion

This method has no effect if aString is empty.

Availability
See Also
Related Sample Code
Declared In
NSCharacterSet.h

formIntersectionWithCharacterSet:

Modifies the receiver so it contains only characters that exist in both the receiver and otherSet.

- (void)formIntersectionWithCharacterSet:(NSCharacterSet *)otherSet

Parameters
otherSet

The character set with which to perform the intersection.

Availability
See Also
Declared In
NSCharacterSet.h

formUnionWithCharacterSet:

Modifies the receiver so it contains all characters that exist in either the receiver or otherSet.

- (void)formUnionWithCharacterSet:(NSCharacterSet *)otherSet

Availability
See Also
Declared In
NSCharacterSet.h

invert

Replaces all the characters in the receiver with all the characters it didn’t previously contain.

- (void)invert

Discussion

Inverting a mutable character set, whether by invert or by invertedSet, is much less efficient than inverting an immutable character set with invertedSet.

Availability
See Also
Declared In
NSCharacterSet.h

removeCharactersInRange:

Removes from the receiver the characters whose Unicode values are in a given range.

- (void)removeCharactersInRange:(NSRange)aRange

Parameters
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.

Availability
See Also
Declared In
NSCharacterSet.h

removeCharactersInString:

Removes from the receiver the characters in a given string.

- (void)removeCharactersInString:(NSString *)aString

Parameters
aString

The characters to remove from the receiver.

Discussion

This method has no effect if aString is empty.

Availability
See Also
Declared In
NSCharacterSet.h

Next Page > Hide TOC


© 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-05-23)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.