<!--
{
  "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/rangeOfCharacter(from:options:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSString(im)rangeOfCharacterFromSet:options:"
  },
  "title" : "rangeOfCharacter(from:options:)"
}
-->

# rangeOfCharacter(from:options:)

Finds and returns the range in the string of the first character, using given options, from a given character set.

```
func rangeOfCharacter(from searchSet: CharacterSet, options mask: NSString.CompareOptions = []) -> NSRange
```

## Parameters

`searchSet`

A character set. This value must not be `nil`.

    Raises an     `NSInvalidArgumentException`     if     `aSet`     is     `nil`    .

`mask`

A mask specifying search options. The following options may be specified by combining them with the C bitwise `OR` operator: [`anchored`](/documentation/Foundation/NSString/CompareOptions/anchored), [`backwards`](/documentation/Foundation/NSString/CompareOptions/backwards).

## Return Value

The range in the receiver of the first character found from `aSet`. Returns a range of `{``NSNotFound``, 0}` if none of the characters in `aSet` are found.

## Discussion

Invokes [`rangeOfCharacter(from:options:range:)`](/documentation/Foundation/NSString/rangeOfCharacter(from:options:range:)) with `mask` for the options and the entire extent of the receiver for the range.

---

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)