---
title: "stringWithCharacters:length:"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nsstring/stringwithcharacters:length:"
---

# stringWithCharacters:length:

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

## Declaration

```occ
+ (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

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

## See Also

### Creating and Initializing Strings

- [string](foundation/nsstring/string.md)
- [init()](foundation/nsstring/init().md)
- [init(bytes:length:encoding:)](foundation/nsstring/init(bytes:length:encoding:).md)
- [init(bytesNoCopy:length:encoding:freeWhenDone:)](foundation/nsstring/init(bytesnocopy:length:encoding:freewhendone:).md)
- [init(characters:length:)](foundation/nsstring/init(characters:length:).md)
- [init(charactersNoCopy:length:freeWhenDone:)](foundation/nsstring/init(charactersnocopy:length:freewhendone:).md)
- [init(string:)](foundation/nsstring/init(string:)-210xa.md)
- [initWithFormat:](foundation/nsstring/initwithformat:.md)
- [init(format:arguments:)](foundation/nsstring/init(format:arguments:).md)
- [initWithFormat:locale:](foundation/nsstring/initwithformat:locale:.md)
- [init(format:locale:arguments:)](foundation/nsstring/init(format:locale:arguments:).md)
- [init(data:encoding:)](foundation/nsstring/init(data:encoding:).md)
- [stringWithFormat:](foundation/nsstring/stringwithformat:.md)
- [localizedStringWithFormat:](foundation/nsstring/localizedstringwithformat:.md)
- [localizedUserNotificationString(forKey:arguments:)](foundation/nsstring/localizedusernotificationstring(forkey:arguments:).md)
