<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSString/range(of:options:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSString(im)rangeOfString:options:"
  },
  "title" : "range(of:options:)"
}
-->

# range(of:options:)

Finds and returns the range of the first occurrence of a given string within the string, subject to given options.

```
func range(of searchString: String, options mask: NSString.CompareOptions = []) -> NSRange
```

## Parameters

`searchString`

The string to search for.

`mask`

A mask specifying search options. For possible values, see [`NSString.CompareOptions`](/documentation/Foundation/NSString/CompareOptions).

## Return Value

An `NSRange` structure giving the location and length in the receiver of the first occurrence of

## Discussion

`searchString`,

modulo the options in `mask`. Returns `{``NSNotFound``, 0}` if

`searchString`

is not found or is empty (`""`).

## Discussion

Invokes [`range(of:options:range:)`](/documentation/Foundation/NSString/range(of:options:range:)) with the options specified by `mask` and the entire extent of the receiver as the range.

`NSString` objects are compared by checking the Unicode canonical equivalence of their code point sequences.  The length of the returned range and that of

`searchString`

may differ if equivalent composed character sequences are matched.

> Important:
> When working with text that’s presented to the user, use the ``doc://com.apple.foundation/documentation/Foundation/NSString/localizedStandardRange(of:)`` method instead.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)