<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "swift: -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/String/init(cString:)-472zs",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SS7cStringSSSays5UInt8VG_tcfc"
  },
  "title" : "init(cString:)"
}
-->

# init(cString:)

Creates a new string by copying the null-terminated UTF-8 data referenced
by the given array.

```
init(cString nullTerminatedUTF8: [UInt8])
```

## Parameters

`nullTerminatedUTF8`


An array containing a null-terminated UTF-8 code unit sequence.

## Discussion

This is identical to `init(cString: [CChar])` but operates on
an unsigned sequence of bytes.

> Note: This initializer is deprecated. Use the initializer
> `String.init(decoding: array, as: UTF8.self)` instead,
> remembering that “\0” is a valid character in Swift.

---

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)