---
title: "getCharacters(_:range:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsstring/getcharacters(_:range:)"
---

# getCharacters(_:range:)

Copies characters from a given range in the receiver into a given buffer.

## Declaration

```swift
func getCharacters(_ buffer: UnsafeMutablePointer<unichar>, range: NSRange)
```

## Parameters

- `buffer`: Upon return, contains the characters from the receiver. buffer must be large enough to contain the characters in the range aRange (aRange.length*sizeof(unichar)).
- `range`: The range of characters to retrieve. The range must not exceed the bounds of the receiver. important: Raises an NSRangeException if any part of aRange lies beyond the bounds of the receiver.

## Discussion

Discussion This method does not add a NULL character. The abstract implementation of this method uses character(at:) repeatedly, correctly extracting the characters, though very inefficiently. Subclasses should override it to provide a fast implementation. 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

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