---
title: "replacingOccurrences(of:with:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsstring/replacingoccurrences(of:with:)"
---

# replacingOccurrences(of:with:)

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

## Declaration

```swift
func replacingOccurrences(of target: String, with replacement: String) -> String
```

## Parameters

- `target`: The string to replace.
- `replacement`: The string with which to replace target.

## Return Value

Return Value A new string in which all occurrences of target in the receiver are replaced by replacement.

## Discussion

Discussion Invokes replacingOccurrences(of:with:options:range:)with 0 options and range of the whole string.

## See Also

### Related Documentation

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

### Replacing Substrings

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