<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFStringFindWithOptions(_:_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@F@CFStringFindWithOptions"
  },
  "title" : "CFStringFindWithOptions(_:_:_:_:_:)"
}
-->

# CFStringFindWithOptions(_:_:_:_:_:)

Searches for a substring within a range of the characters represented by a string and, if the substring is found, returns its range within the object’s characters.

```
func CFStringFindWithOptions(_ theString: CFString!, _ stringToFind: CFString!, _ rangeToSearch: CFRange, _ searchOptions: CFStringCompareFlags, _ result: UnsafeMutablePointer<CFRange>!) -> Bool
```

## Parameters

`theString`

The string in which to to search for `stringToFind`.

`stringToFind`

The substring to search for in `theString`.

`rangeToSearch`

A range of the characters to search in `theString`. The specified range must not exceed the length of the string.

`searchOptions`

The option flags to control the search behavior. See [String Comparison Flags](/documentation/CoreFoundation/string-comparison-flags) for possible values. The flags [`compareNumerically`](/documentation/CoreFoundation/CFStringCompareFlags/compareNumerically) and [`compareForcedOrdering`](/documentation/CoreFoundation/CFStringCompareFlags/compareForcedOrdering) are ignored.

`result`

On return, if the function result is `true`, contains the starting location and length of the found substring. You may pass `NULL` if you only want to know if the substring exists in the larger string.

## Return Value

`true` if the substring was found, `false` otherwise.

## Discussion

This function allows you to search only part of the characters of a string for a substring. It returns the found range indirectly, in the final `result` parameter. If you want to know if the entire range of characters represented by a string contains a particular substring, you can use the convenience function [`CFStringFind(_:_:_:)`](/documentation/CoreFoundation/CFStringFind(_:_:_:)). Both of these functions return upon finding the first occurrence of the substring, so if you want to find out about multiple occurrences, call the [`CFStringCreateArrayWithFindResults(_:_:_:_:_:)`](/documentation/CoreFoundation/CFStringCreateArrayWithFindResults(_:_:_:_:_:)) function.

Depending on the comparison-option flags specified, the length of the resulting range might be different than the length of the search string.

---

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)