Class

NSCharacterSet

An object representing a fixed set of Unicode character values for use in search operations.

Declaration

@interface NSCharacterSet : NSObject

Overview

An NSCharacterSet object represents a set of Unicode-compliant characters. NSString and NSScanner objects use NSCharacterSet objects to group characters together for searching operations, so that they can find any of a particular set of characters during a search. The cluster’s two public classes, NSCharacterSet and NSMutableCharacterSet, declare the programmatic interface for static and dynamic character sets, respectively.

The objects you create using these classes are referred to as character set objects (and when no confusion will result, merely as character sets). Because of the nature of class clusters, character set objects aren’t actual instances of the NSCharacterSet or NSMutableCharacterSet classes but of one of their private subclasses. Although a character set object’s class is private, its interface is public, as declared by these abstract superclasses, NSCharacterSet and NSMutableCharacterSet. The character set classes adopt the NSCopying and NSMutableCopying protocols, making it convenient to convert a character set of one type to the other.

The NSCharacterSet class declares the programmatic interface for an object that manages a set of Unicode characters (see the NSString class cluster specification for information on Unicode). NSCharacterSet’s principal primitive method, characterIsMember:, provides the basis for all other instance methods in its interface. A subclass of NSCharacterSet needs only to implement this method, plus mutableCopyWithZone:, for proper behavior. For optimal performance, a subclass should also override bitmapRepresentation, which otherwise works by invoking characterIsMember: for every possible Unicode value.

NSCharacterSet is “toll-free bridged” with its Core Foundation counterpart, CFCharacterSetRef. See Toll-Free Bridging for more information on toll-free bridging.

Topics

Getting Standard Character Sets

alphanumericCharacterSet

A character set containing the characters in Unicode General Categories L*, M*, and N*.

capitalizedLetterCharacterSet

A character set containing the characters in Unicode General Category Lt.

controlCharacterSet

A character set containing the characters in Unicode General Category Cc and Cf.

decimalDigitCharacterSet

A character set containing the characters in the category of Decimal Numbers.

decomposableCharacterSet

A character set containing individual Unicode characters that can also be represented as composed character sequences (such as for letters with accents), by the definition of “standard decomposition” in version 3.2 of the Unicode character encoding standard.

illegalCharacterSet

A character set containing values in the category of Non-Characters or that have not yet been defined in version 3.2 of the Unicode standard.

letterCharacterSet

A character set containing the characters in Unicode General Category L* & M*.

lowercaseLetterCharacterSet

A character set containing the characters in Unicode General Category Ll.

newlineCharacterSet

A character set containing the newline characters (U+000A ~ U+000D, U+0085, U+2028, and U+2029).

nonBaseCharacterSet

A character set containing the characters in Unicode General Category M*.

punctuationCharacterSet

A character set containing the characters in Unicode General Category P*.

symbolCharacterSet

A character set containing the characters in Unicode General Category S*.

uppercaseLetterCharacterSet

A character set containing the characters in Unicode General Category Lu and Lt.

whitespaceAndNewlineCharacterSet

A character set containing characters in Unicode General Category Z*, U+000A ~ U+000D, and U+0085.

whitespaceCharacterSet

A character set containing the characters in Unicode General Category Zs and CHARACTER TABULATION (U+0009).

Getting Character Sets for URL Encoding

URLFragmentAllowedCharacterSet

Returns the character set for characters allowed in a fragment URL component.

URLHostAllowedCharacterSet

Returns the character set for characters allowed in a host URL subcomponent.

URLPasswordAllowedCharacterSet

Returns the character set for characters allowed in a password URL subcomponent.

URLPathAllowedCharacterSet

Returns the character set for characters allowed in a path URL component.

URLQueryAllowedCharacterSet

Returns the character set for characters allowed in a query URL component.

URLUserAllowedCharacterSet

Returns the character set for characters allowed in a user URL subcomponent.

Creating a Custom Character Set

+ characterSetWithCharactersInString:

Returns a character set containing the characters in a given string.

+ characterSetWithRange:

Returns a character set containing characters with Unicode values in a given range.

NSOpenStepUnicodeReservedBase

Specifies lower bound for a Unicode character range reserved for Apple’s corporate use.

Creating and Managing Character Sets as Bitmap Representations

+ characterSetWithBitmapRepresentation:

Returns a character set containing characters determined by a given bitmap representation.

+ characterSetWithContentsOfFile:

Returns a character set read from the bitmap representation stored in the file a given path.

bitmapRepresentation

An NSData object encoding the receiver in binary format.

Inverting a Character Set

invertedSet

A character set containing only characters that don’t exist in the receiver.

Testing Set Membership

- characterIsMember:

Returns a Boolean value that indicates whether a given character is in the receiver.

- hasMemberInPlane:

Returns a Boolean value that indicates whether the receiver has at least one member in a given character plane.

- isSupersetOfSet:

Returns a Boolean value that indicates whether the receiver is a superset of another given character set.

- longCharacterIsMember:

Returns a Boolean value that indicates whether a given long character is a member of the receiver.

Relationships

Inherits From

See Also

Characters

NSMutableCharacterSet

An object representing a mutable set of Unicode character values for use in search operations.

unichar

Type for UTF-16 code units.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software