<!--
{
  "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/init(characters:length:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSString(im)initWithCharacters:length:"
  },
  "title" : "init(characters:length:)"
}
-->

# init(characters:length:)

Returns an initialized `NSString` object that contains a given number of characters from a given C array of UTF-16 code units.

```
convenience init(characters: UnsafePointer<unichar>, length: Int)
```

## Parameters

`characters`

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

`length`

The number of characters to use from `characters`.

## Return Value

An initialized `NSString` object containing `length` characters taken from `characters`. The returned object may be different from the original receiver.

## See Also

[`+  stringWithCharacters:length:`](/documentation/Foundation/NSString/stringWithCharacters:length:)

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



---

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)