<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/AttributedString/replaceSelection(_:withCharacters:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation16AttributedStringV7SwiftUIE16replaceSelection_14withCharactersyAD0b4TextG0Vz_xtSlRzSJ7ElementRtzlF"
  },
  "title" : "replaceSelection(_:withCharacters:)"
}
-->

# replaceSelection(_:withCharacters:)

Replace the selection with new content, attributed with the typing
attributes.

```
mutating func replaceSelection(_ selection: inout AttributedTextSelection, withCharacters newContent: some Collection<Character>)
```

## Discussion

Operates just like [`replaceSelection(_:with:)`](/documentation/Foundation/AttributedString/replaceSelection(_:with:)), but applies
the typing attributes to the new content before inserting it.

---

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)