<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFStringGetCString(_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@F@CFStringGetCString"
  },
  "title" : "CFStringGetCString(_:_:_:_:)"
}
-->

# CFStringGetCString(_:_:_:_:)

Copies the character contents of a string to a local C string buffer after converting the characters to a given encoding.

```
func CFStringGetCString(_ theString: CFString!, _ buffer: UnsafeMutablePointer<CChar>!, _ bufferSize: CFIndex, _ encoding: CFStringEncoding) -> Bool
```

## Parameters

`theString`

The string whose contents you wish to access.

`buffer`

The C string buffer into which to copy the string. On return, the buffer contains the converted characters. If there is an error in conversion, the buffer contains only partial results.

    The buffer must be large enough to contain the converted characters and a     `NUL`     terminator. For example, if the string is     `Toby`    , the buffer must be at least 5 bytes long.

`bufferSize`

The length of `buffer` in bytes.

`encoding`

The string encoding to which the character contents of `theString` should be converted. The encoding must specify an 8-bit encoding.

## Return Value

`true` upon success or `false` if the conversion fails or the provided buffer is too small.

## Discussion

This function is useful when you need your own copy of a string’s character data as a C string. You also typically call it as a “backup” when a prior call to the [`CFStringGetCStringPtr(_:_:)`](/documentation/CoreFoundation/CFStringGetCStringPtr(_:_:)) function fails.

---

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)