---
title: "insert(_:at:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsmutablestring/insert(_:at:)"
---

# insert(_:at:)

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

## Declaration

```swift
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

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.

## 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)
- [replaceCharacters(in:with:)](foundation/nsmutablestring/replacecharacters(in:with:).md)
- [replaceOccurrences(of:with:options:range:)](foundation/nsmutablestring/replaceoccurrences(of:with:options:range:).md)
- [setString(_:)](foundation/nsmutablestring/setstring(_:).md)
