---
title: "replaceCharacters(in:with:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsmutablestring/replacecharacters(in:with:)"
---

# replaceCharacters(in:with:)

Replaces the characters from range with those in aString.

## Declaration

```swift
func replaceCharacters(in range: NSRange, with aString: String)
```

## Parameters

- `range`: The range of characters to replace. range must not exceed the bounds of the receiver. important: Raises an NSRangeException if any part of range lies beyond the end of the receiver.
- `aString`: The string with which to replace the characters in range. aString must not be nil.

## Discussion

Discussion This method treats the length of the string as a valid range value that returns an empty string.

## See Also

### Modifying a String

- [append(_:)](foundation/nsmutablestring/append(_:).md)
- [applyTransform(_:reverse:range:updatedRange:)](foundation/nsmutablestring/applytransform(_:reverse:range:updatedrange:).md)
- [deleteCharacters(in:)](foundation/nsmutablestring/deletecharacters(in:).md)
- [insert(_:at:)](foundation/nsmutablestring/insert(_:at:).md)
- [replaceOccurrences(of:with:options:range:)](foundation/nsmutablestring/replaceoccurrences(of:with:options:range:).md)
- [setString(_:)](foundation/nsmutablestring/setstring(_:).md)
