<!--
{
  "availability" : [
    "iOS: 2.0.0 - 2.0.0",
    "iPadOS: 2.0.0 - 2.0.0",
    "tvOS: 9.0.0 - 9.0.0",
    "visionOS: 1.0.0 - 1.0.0",
    "watchOS: 2.0.0 - 2.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSString/string(withCString:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSString(cm)stringWithCString:"
  },
  "title" : "string(withCString:)"
}
-->

# string(withCString:)

Creates a new string using a given C-string.

```
class func string(withCString bytes: UnsafePointer<CChar>) -> Any?
```

## Discussion

`cString` should contain data in the default C string encoding. If the argument passed to [`string(withCString:)`](/documentation/Foundation/NSString/string(withCString:)) is not a zero-terminated C-string, the results are undefined.

## See Also



---

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)