---
title: "removeAll(keepingCapacity:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/string/removeall(keepingcapacity:)"
---

# removeAll(keepingCapacity:)

Replaces this string with the empty string.

## Declaration

```swift
mutating func removeAll(keepingCapacity keepCapacity: Bool = false)
```

## Parameters

- `keepCapacity`: Pass true to prevent the release of the string’s allocated storage. Retaining the storage can be a useful optimization when you’re planning to grow the string again. The default value is false.

## Discussion

Discussion Calling this method invalidates any existing indices for use with this string.

## See Also

### Removing Substrings

- [remove(at:)](swift/string/remove(at:).md)
- [remove(at:)](swift/string/remove(at:)-5g0wm.md)
- [removeAll(where:)](swift/string/removeall(where:).md)
- [removeFirst()](swift/string/removefirst().md)
- [removeFirst(_:)](swift/string/removefirst(_:).md)
- [removeLast()](swift/string/removelast().md)
- [removeLast(_:)](swift/string/removelast(_:).md)
- [removeSubrange(_:)](swift/string/removesubrange(_:).md)
- [removeSubrange(_:)](swift/string/removesubrange(_:)-8maxn.md)
- [removeSubrange(_:)](swift/string/removesubrange(_:)-9twng.md)
- [drop(while:)](swift/string/drop(while:).md)
- [dropFirst(_:)](swift/string/dropfirst(_:).md)
- [dropLast(_:)](swift/string/droplast(_:).md)
- [popLast()](swift/string/poplast().md)
