---
title: "character(at:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsstring/character(at:)"
---

# character(at:)

Returns the character at a given UTF-16 code unit index.

## Declaration

```swift
func character(at index: Int) -> unichar
```

## Parameters

- `index`: The index of the character to retrieve. important: Raises an NSRangeException if index lies beyond the end of the receiver.

## Return Value

Return Value The character at the array position given by index.

## Discussion

Discussion You should always use the rangeOfComposedCharacterSequence(at:) or rangeOfComposedCharacterSequences(for:) method to determine character boundaries, so that any surrogate pairs or character clusters are handled correctly.

## See Also

### Getting Characters and Bytes

- [getCharacters(_:range:)](foundation/nsstring/getcharacters(_:range:).md)
- [getBytes(_:maxLength:usedLength:encoding:options:range:remaining:)](foundation/nsstring/getbytes(_:maxlength:usedlength:encoding:options:range:remaining:).md)
