---
title: "replacingOccurrences(of:with:options:range:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/stringprotocol/replacingoccurrences(of:with:options:range:)"
---

# replacingOccurrences(of:with:options:range:)

Returns a new string in which all occurrences of a target string in a specified range of the string are replaced by another given string.

## Declaration

```swift
func replacingOccurrences<Target, Replacement>(of target: Target, with replacement: Replacement, options: String.CompareOptions = [], range searchRange: Range<Self.Index>? = nil) -> String where Target : StringProtocol, Replacement : StringProtocol
```
