These values represent the options available to many of the string classes’ search and comparison methods.


See Searching, Comparing, and Sorting Strings for details on the effects of these options.



static var literal: NSString.CompareOptions

Exact character-by-character equivalence.

static var backwards: NSString.CompareOptions

Search from end of source string.

static var anchored: NSString.CompareOptions

Search is limited to start (or end, if NSBackwardsSearch) of source string.

static var numeric: NSString.CompareOptions

Numbers within strings are compared using numeric value, that is, Name2.txt < Name7.txt < Name25.txt.

static var widthInsensitive: NSString.CompareOptions

Search ignores width differences in characters that have full-width and half-width forms, as occurs in East Asian character sets.

static var forcedOrdering: NSString.CompareOptions

Comparisons are forced to return either NSOrderedAscending or NSOrderedDescending if the strings are equivalent but not strictly equal.

static var regularExpression: NSString.CompareOptions

The search string is treated as an ICU-compatible regular expression. If set, no other options can apply except caseInsensitive and anchored. You can use this option only with the rangeOfString:... methods and replacingOccurrences(of:with:options:range:).


Conforms To

See Also

Identifying and Comparing Strings

func caseInsensitiveCompare(String)

Returns the result of invoking compare(_:options:) with NSCaseInsensitiveSearch as the only option.

func localizedCaseInsensitiveCompare(String)

Compares the string with a given string using a case-insensitive, localized, comparison.

func compare(String)

Returns the result of invoking compare(_:options:range:) with no options and the receiver’s full extent as the range.

func localizedCompare(String)

Compares the string and a given string using a localized comparison.

func compare(String, options: NSString.CompareOptions = [])

Compares the string with the specified string using the given options.

func compare(String, options: NSString.CompareOptions = [], range: NSRange, locale: Any?)

Compares the string using the specified options and returns the lexical ordering for the range.

func localizedStandardCompare(String)

Compares strings as sorted by the Finder.

func hasPrefix(String)

Returns a Boolean value that indicates whether a given string matches the beginning characters of the receiver.

func hasSuffix(String)

Returns a Boolean value that indicates whether a given string matches the ending characters of the receiver.

func isEqual(to: String)

Returns a Boolean value that indicates whether a given string is equal to the receiver using a literal Unicode-based comparison.

var hash: Int

An unsigned integer that can be used as a hash table address.

struct NSString.EncodingConversionOptions

Options for converting string encodings.