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

# replaceSubrange(_:with:)

Replaces a region of bytes in the data with new bytes from a buffer.

## Declaration

```swift
mutating func replaceSubrange<SourceType>(_ subrange: Range<Data.Index>, with buffer: UnsafeBufferPointer<SourceType>)
```

## Parameters

- `subrange`: The range in the data to replace.
- `buffer`: The replacement bytes.

## Discussion

Discussion This will resize the data if required, to fit the entire contents of buffer. Precondition: The bounds of subrange must be valid indices of the collection.

## See Also

### Replacing a Range of Bytes

- [replaceSubrange(_:with:)](foundation/data/replacesubrange(_:with:)-9u7ry.md)
- [replaceSubrange(_:with:count:)](foundation/data/replacesubrange(_:with:count:).md)
