---
title: "rangeOfCharacter(from:options:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsstring/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.

## Declaration

```swift
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: doc://com.apple.foundation/documentation/Foundation/NSString/CompareOptions/anchored, doc://com.apple.foundation/documentation/Foundation/NSString/CompareOptions/backwards.

## Return Value

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

Discussion Invokes rangeOfCharacter(from:options:range:) with mask for the options and the entire extent of the receiver for the range.

## 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: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:)](foundation/nsstring/range(of:options:range:).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)
