<!--
{
  "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/stringWithCharacters:length:",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSString(cm)stringWithCharacters:length:"
  },
  "title" : "stringWithCharacters:length:"
}
-->

# stringWithCharacters:length:

Returns a string containing a given number of characters taken from a given C array of UTF-16 code units.

```
+ (instancetype) stringWithCharacters:(const unichar *) characters length:(NSUInteger) length;
```

## Parameters

`characters`

A C array of UTF-16 code units; the value must not be `NULL`.
  
  > Important:
  > Raises an exception if `chars` is `NULL`, even if `length` is `0`.

`length`

The number of characters to use from `chars`.

## Return Value

A string containing `length` UTF-16 code units taken (starting with the first) from `chars`.

---

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)