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

# replaceSubrange(_:with:)

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

## Declaration

```swift
mutating func replaceSubrange(_ subrange: Range<Data.Index>, with newElements: some ContiguousBytes & Collection<UInt8>)
```

## Parameters

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

## Discussion

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