---
title: "replacingOccurrences(of:with:options:range:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsstring/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 receiver are replaced by another given string.

## Declaration

```swift
func replacingOccurrences(of target: String, with replacement: String, options: NSString.CompareOptions = [], range searchRange: NSRange) -> String
```

## Parameters

- `target`: The string to replace.
- `replacement`: The string with which to replace target.
- `options`: A mask of options to use when comparing target with the receiver. Pass 0 to specify no options.
- `searchRange`: The range in the receiver in which to search for target.

## Return Value

Return Value A new string in which all occurrences of target, matched using options, in searchRange of the receiver are replaced by replacement.

## See Also

### Related Documentation

- [replacingPercentEscapes(using:)](foundation/nsstring/replacingpercentescapes(using:).md)

### Replacing Substrings

- [replacingOccurrences(of:with:)](foundation/nsstring/replacingoccurrences(of:with:).md)
- [replacingCharacters(in:with:)](foundation/nsstring/replacingcharacters(in:with:).md)
