<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/String/remove(at:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SS6remove2atSJSS5IndexV_tF"
  },
  "title" : "remove(at:)"
}
-->

# remove(at:)

Removes and returns the character at the specified position.

```
@discardableResult mutating func remove(at i: String.Index) -> Character
```

## Parameters

`i`

The position of the character to remove. `i` must be a
valid index of the string that is not equal to the string’s end index.

## Return Value

The character that was removed.

## Discussion

All the elements following `i` are moved to close the gap. This example
removes the hyphen from the middle of a string.

```
var nonempty = "non-empty"
if let i = nonempty.firstIndex(of: "-") {
    nonempty.remove(at: i)
}
print(nonempty)
// Prints "nonempty"
```

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

---

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)