---
title: "replaceCharacters(in:with:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsmutableattributedstring/replacecharacters(in:with:)-1uaw7"
---

# replaceCharacters(in:with:)

Replaces the characters and attributes in a given range with the characters and attributes of the given attributed string.

## Declaration

```swift
func replaceCharacters(in range: NSRange, with attrString: NSAttributedString)
```

## Parameters

- `range`: The range of characters and attributes replaced.
- `attrString`: The attributed string whose characters and attributes replace those in the specified range.

## Discussion

Discussion Raises an rangeException if any part of range lies beyond the end of the receiver’s characters.

## See Also

### Changing Characters and Attributes

- [append(_:)](foundation/nsmutableattributedstring/append(_:).md)
- [insert(_:at:)](foundation/nsmutableattributedstring/insert(_:at:).md)
- [setAttributedString(_:)](foundation/nsmutableattributedstring/setattributedstring(_:).md)
