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

# CFStringFind(_:_:_:)

Searches for a substring within a string and, if it is found, yields the range of the substring within the object’s characters.

```
func CFStringFind(_ theString: CFString!, _ stringToFind: CFString!, _ compareOptions: CFStringCompareFlags) -> CFRange
```

## Parameters

`theString`

The string in which to search for `stringToFind`.

`stringToFind`

The string to search for in `theString`.

`compareOptions`

Flags that select different types of comparisons, such as localized comparison, case-insensitive comparison, and non-literal comparison. If you want the default comparison behavior, pass `0`. See [String Comparison Flags](/documentation/CoreFoundation/string-comparison-flags) for the available flags.

## Return Value

The range of the located substring within `theString`. If a match is not located, the returned [`CFRange`](/documentation/CoreFoundation/CFRange) structure will have a location of [`kCFNotFound`](/documentation/CoreFoundation/kCFNotFound) and a length of `0` (either of which is enough to indicate failure).

## Discussion

This function is a convenience when you want to know if the entire range of characters represented by a string contains a particular substring. If you want to search only part of the characters of a string, use the [`CFStringFindWithOptions(_:_:_:_:_:)`](/documentation/CoreFoundation/CFStringFindWithOptions(_:_:_:_:_:)) function. 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)