---
title: "replaceSubrange(_:with:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/attributedstring/replacesubrange(_:with:)"
---

# replaceSubrange(_:with:)

Replaces the contents in a range of the attributed string.

## Declaration

```swift
mutating func replaceSubrange(_ range: some RangeExpression<AttributedString.Index>, with s: some AttributedStringProtocol)
```

## Parameters

- `range`: The range of the attributed string to replace.
- `s`: The string to insert in place of the replaced range.

## See Also

### Modifying an Attributed String

- [insert(_:at:)](foundation/attributedstring/insert(_:at:).md)
- [AttributedString.Index](foundation/attributedstring/index.md)
- [removeSubrange(_:)](foundation/attributedstring/removesubrange(_:).md)
