<!--
{
  "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/replacingCharacters(in:with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSString(im)stringByReplacingCharactersInRange:withString:"
  },
  "title" : "replacingCharacters(in:with:)"
}
-->

# replacingCharacters(in:with:)

Returns a new string in which the characters in a specified range of the receiver are replaced by a given string.

```
func replacingCharacters(in range: NSRange, with replacement: String) -> String
```

## Parameters

`range`

A range of characters in the receiver.

`replacement`

The string with which to replace the characters in `range`.

## Return Value

A new string in which the characters in `range` of the receiver are replaced by `replacement`.

## See Also

[`-  stringByReplacingPercentEscapesUsingEncoding:`](/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)