---
title: "replaceCharacters(in:withRTFD:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nstext/replacecharacters(in:withrtfd:)"
---

# replaceCharacters(in:withRTFD:)

Replaces the characters in the given range with RTFD text interpreted from the given RTFD data.

## Declaration

```swift
func replaceCharacters(in range: NSRange, withRTFD rtfdData: Data)
```

## Parameters

- `range`: The range of characters to be replaced.
- `rtfdData`: The RTFD data from which to derive the replacement string.

## Discussion

Discussion This method applies only to rich text objects. This method does not include undo support by default. Clients must invoke shouldChangeText(inRanges:replacementStrings:) or shouldChangeText(in:replacementString:) to include this method in an undoable action. This method is designed for transferring text from out-of-process sources such as the pasteboard. In most cases, programmatic modification of the text is best done by operating on the text storage directly, using the general methods of NSMutableAttributedString.

## See Also

### Replacing text

- [replaceCharacters(in:withRTF:)](appkit/nstext/replacecharacters(in:withrtf:).md)
- [replaceCharacters(in:with:)](appkit/nstext/replacecharacters(in:with:).md)
