<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSString/replacingOccurrences(of:with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSString(im)stringByReplacingOccurrencesOfString:withString:"
  },
  "title" : "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.

```
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

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

## Discussion

Invokes [`replacingOccurrences(of:with:options:range:)`](/documentation/Foundation/NSString/replacingOccurrences(of:with:options:range:))with `0` options and range of the whole string.

## See Also

[`replacingPercentEscapes(using:)`](/documentation/Foundation/NSString/replacingPercentEscapes(using:))

Returns a new string made by replacing in the receiver all percent escapes with the matching characters as determined by a given encoding.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)