<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextFinderClient/replaceCharacters(in:with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextFinderClient(im)replaceCharactersInRange:withString:"
  },
  "title" : "replaceCharacters(in:with:)"
}
-->

# replaceCharacters(in:with:)

Replaces the text in the specified range with the new string.

```
optional func replaceCharacters(in range: NSRange, with string: String)
```

## Parameters

`range`

The specified range of the text to replace.

`string`

The replacement string.

## Discussion

See [`NSTextFinder`](/documentation/AppKit/NSTextFinder) for a complete description.

---

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)