Class

NSScanner

A string parser that scans for substrings or characters in a character set, and for numeric values from decimal, hexadecimal, and floating-point representations.

Declaration

@interface NSScanner : NSObject

Overview

An NSScanner object interprets and converts the characters of an NSString object into number and string values. You assign the scanner’s string when you create the scanner, and the scanner progresses through the characters of that string from beginning to end as you request items.

Because of the nature of class clusters, a scanner object isn’t an actual instance of the NSScanner class, but is one of its private subclasses. Although a scanner object’s class is private, its interface is public, as declared by this abstract superclass, NSScanner. The objects you create using this class are referred to as scanner objects (and when no confusion will result, merely as scanners).

To set an NSScanner object to ignore a set of characters as it scans the string, use the charactersToBeSkipped property. Characters in the skip set are skipped over before the target is scanned. The default set of characters to skip is the whitespace and newline character set.

To retrieve the unscanned remainder of the string, use [[scanner string] substringFromIndex: [scanner scanLocation]].

Topics

Creating a Scanner

+ scannerWithString:

Returns an NSScanner object that scans a given string.

+ localizedScannerWithString:

Returns an NSScanner object that scans a given string according to the user’s default locale.

- initWithString:

Returns an NSScanner object initialized to scan a given string.

Getting a Scanner’s String

string

The string the scanner will scan.

Configuring a Scanner

scanLocation

The character position at which the receiver will begin its next scanning operation.

caseSensitive

Flag that indicates whether the receiver distinguishes case in the characters it scans.

charactersToBeSkipped

Character set containing the characters the scanner ignores when looking for a scannable element.

locale

The locale to use when scanning.

Scanning Characters and Strings

- scanCharactersFromSet:intoString:

Scans the string as long as characters from a given character set are encountered, accumulating characters into a string that’s returned by reference.

- scanUpToCharactersFromSet:intoString:

Scans the string until a character from a given character set is encountered, accumulating characters into a string that’s returned by reference.

- scanString:intoString:

Scans a given string, returning an equivalent string object by reference if a match is found.

- scanUpToString:intoString:

Scans the string until a given string is encountered, accumulating characters into a string that’s returned by reference.

Scanning Numeric Values

- scanDecimal:

Scans for an NSDecimal value, returning a found value by reference.

- scanDouble:

Scans for a double value, returning a found value by reference.

- scanFloat:

Scans for a float value, returning a found value by reference.

- scanHexDouble:

Scans for a double value from a hexadecimal representation, returning a found value by reference.

- scanHexFloat:

Scans for a double value from a hexadecimal representation, returning a found value by reference.

- scanHexInt:

Scans for an unsigned value from a hexadecimal representation, returning a found value by reference.

- scanHexLongLong:

Scans for a long long value from a hexadecimal representation, returning a found value by reference.

- scanInteger:

Scans for an NSInteger value from a decimal representation, returning a found value by reference

- scanInt:

Scans for an int value from a decimal representation, returning a found value by reference.

- scanLongLong:

Scans for a long long value from a decimal representation, returning a found value by reference.

- scanUnsignedLongLong:

Scans for an unsigned long long value from a decimal representation, returning a found value by reference.

Monitoring Scanner Progress

atEnd

Flag that indicates whether the receiver has exhausted all significant characters.

Relationships

Inherits From

Conforms To

See Also

Pattern Matching

NSRegularExpression

An immutable representation of a compiled regular expression that you apply to Unicode strings.

NSDataDetector

A specialized regular expression object that matches natural language text for predefined data patterns.

NSTextCheckingResult

An occurrence of textual content found during the analysis of a block of text, such as when matching a regular expression.

NSNotFound

A value indicating that a requested item couldn’t be found or doesn’t exist.

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