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

# CFStringReplace(_:_:_:)

Replaces part of the character contents of a CFMutableString object with another string.

```
func CFStringReplace(_ theString: CFMutableString!, _ range: CFRange, _ replacement: CFString!)
```

## Parameters

`theString`

The string to modify. The characters are adjusted left or right (depending on the length of the substituted string) and the character buffer of the object is resized accordingly. If this value is not a CFMutableString object, an assertion is raised.

`range`

The range of characters in `theString` to replace.

`replacement`

The replacement string to put into `theString`.

## Discussion

Although you can use this function to replace all characters in a CFMutableString object (by specifying a range of `(0, CFStringGetLength(theString))` ), it is more convenient to use the [`CFStringReplaceAll(_:_:)`](/documentation/CoreFoundation/CFStringReplaceAll(_:_:)) function for that purpose.

---

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)