<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSMutableString/insert(_:at:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMutableString(im)insertString:atIndex:"
  },
  "title" : "insert(_:at:)"
}
-->

# insert(_:at:)

Inserts into the receiver the characters of a given string at a given location.

```
func insert(_ aString: String, at loc: Int)
```

## Parameters

`aString`

The string to insert into the receiver. `aString` must not be `nil`.

`loc`

The location at which `aString` is inserted. The location must not exceed the bounds of the receiver.
  
  > Important:
  > Raises an `NSRangeException` if `loc` lies beyond the end of the string.

## Discussion

The new characters begin at `loc` and the existing characters from `loc` to the end are shifted by the length of `aString`.

This method treats the length of the string as a valid index value that returns an empty 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)