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

# CFStringCompareWithOptionsAndLocale(_:_:_:_:_:)

Compares a range of the characters in one string with another string using a given locale.

```
func CFStringCompareWithOptionsAndLocale(_ theString1: CFString!, _ theString2: CFString!, _ rangeToCompare: CFRange, _ compareOptions: CFStringCompareFlags, _ locale: CFLocale!) -> CFComparisonResult
```

## Parameters

`theString1`

The first string to use in the comparison.

`theString2`

The second string to use in the comparison. The full range of this string is used.

`rangeToCompare`

The range of characters in `theString1` to be used in the comparison to `theString2`. To use the whole string, pass the range `CFRangeMake(0, CFStringGetLength(theString1))`. The specified range must not exceed the bounds of the string.

`compareOptions`

Flags that select different types of comparisons, such as case-insensitive comparison and non-literal comparison. See [String Comparison Flags](/documentation/CoreFoundation/string-comparison-flags) for the available flags.

    Specifying the     `kCFCompareBackwards`     or     `kCFCompareAnchored`     option has no effect.

    Specifying the     `kCFCompareLocalized`     option and passing     `NULL`     for     `locale`     causes the current locale (the return value of [`CFLocaleCopyCurrent()`](/documentation/CoreFoundation/CFLocaleCopyCurrent())    ) to be used.

`locale`

The locale to use for the comparison, which affects both equality and ordering algorithms. For example, in some locales, accented characters are ordered immediately after the base; other locales order them after “z”.

    If     `NULL`     and the     `kCFCompareLocalized`     option is not specified for     `compareOptions`    , the comparison is nonlocalized.

## Return Value

A [`CFComparisonResult`](/documentation/CoreFoundation/CFComparisonResult) value that indicates whether `theString1` is equal to, less than, or greater than `theString2`.

## Discussion

---

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)