<!--
{
  "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/NSString/getCharacters(_:range:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSString(im)getCharacters:range:"
  },
  "title" : "getCharacters(_:range:)"
}
-->

# getCharacters(_:range:)

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

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

This method does not add a `NULL` character.

The abstract implementation of this method uses [`character(at:)`](/documentation/Foundation/NSString/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:)`](/documentation/Foundation/NSString/rangeOfComposedCharacterSequence(at:)) or [`rangeOfComposedCharacterSequences(for:)`](/documentation/Foundation/NSString/rangeOfComposedCharacterSequences(for:)) method to determine character boundaries, so that any surrogate pairs or character clusters are handled correctly.

---

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)