---
title: "replacing(_:with:subrange:maxReplacements:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/rangereplaceablecollection/replacing(_:with:subrange:maxreplacements:)-1uswm"
---

# replacing(_:with:subrange:maxReplacements:)

Returns a new collection in which all occurrences of a target sequence are replaced by another collection.

## Declaration

```swift
func replacing<C, Replacement>(_ other: C, with replacement: Replacement, subrange: Range<Self.Index>, maxReplacements: Int = .max) -> Self where C : Collection, Replacement : Collection, Self.Element == C.Element, C.Element == Replacement.Element
```

## Parameters

- `other`: The sequence to replace.
- `replacement`: The new elements to add to the collection.
- `subrange`: The range in the collection in which to search for other.
- `maxReplacements`: A number specifying how many occurrences of other to replace. Default is Int.max.

## Return Value

Return Value A new collection in which all occurrences of other in subrange of the collection are replaced by replacement.
