---
title: "range(of:options:range:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsstring/range(of:options:range:)"
---

# range(of:options:range:)

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

## Declaration

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

## Parameters

- `searchString`: The string for which to search.
- `mask`: A mask specifying search options. The following options may be specified by combining them with the C bitwise OR operator: NSCaseInsensitiveSearch, NSLiteralSearch, NSBackwardsSearch, and NSAnchoredSearch. See https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Strings/introStrings.html#//apple_ref/doc/uid/10000035i for details on these options.
- `rangeOfReceiverToSearch`: The range within the receiver for which to search for aString. Raises an NSRangeException if rangeOfReceiverToSearch is invalid.

## Return Value

Return Value An NSRange structure giving the location and length in the receiver of

## Discussion

Discussion searchString within rangeOfReceiverToSearch in the receiver, modulo the options in mask. The range returned is relative to the start of the string, not to the passed-in range. Returns {``NSNotFound``, 0} if searchString is not found or is empty (""). Discussion NSString objects are compared by checking the Unicode canonical equivalence of their code point sequences. T he 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 localizedStandardRange(of:) method instead.

## See Also

### Finding Characters and Substrings

- [contains(_:)](foundation/nsstring/contains(_:).md)
- [localizedCaseInsensitiveContains(_:)](foundation/nsstring/localizedcaseinsensitivecontains(_:).md)
- [localizedStandardContains(_:)](foundation/nsstring/localizedstandardcontains(_:).md)
- [rangeOfCharacter(from:)](foundation/nsstring/rangeofcharacter(from:).md)
- [rangeOfCharacter(from:options:)](foundation/nsstring/rangeofcharacter(from:options:).md)
- [rangeOfCharacter(from:options:range:)](foundation/nsstring/rangeofcharacter(from:options:range:).md)
- [range(of:)](foundation/nsstring/range(of:).md)
- [range(of:options:)](foundation/nsstring/range(of:options:).md)
- [range(of:options:range:locale:)](foundation/nsstring/range(of:options:range:locale:).md)
- [localizedStandardRange(of:)](foundation/nsstring/localizedstandardrange(of:).md)
- [enumerateLines(_:)](foundation/nsstring/enumeratelines(_:).md)
- [enumerateSubstrings(in:options:using:)](foundation/nsstring/enumeratesubstrings(in:options:using:).md)
