CFStringGetCString(_:_:_:_:)
Copies the character contents of a string to a local C string buffer after converting the characters to a given encoding.
Declaration
func CFStringGetCString(_ theString: CFString!, _ buffer: UnsafeMutablePointer<CChar>!, _ bufferSize: CFIndex, _ encoding: CFStringEncoding) -> BoolParameters
- 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
NULterminator. For example, if the string isToby, the buffer must be at least 5 bytes long. - bufferSize:
The length of
bufferin bytes. - encoding:
The string encoding to which the character contents of
theStringshould 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(_:_:) function fails.
See Also
Accessing Characters
CFStringCreateExternalRepresentation(_:_:_:_:)CFStringGetBytes(_:_:_:_:_:_:_:_:)CFStringGetCharacterAtIndex(_:_:)CFStringGetCharacters(_:_:_:)CFStringGetCharactersPtr(_:)CFStringGetCharacterFromInlineBuffer(_:_:)CFStringGetCStringPtr(_:_:)CFStringGetLength(_:)CFStringGetPascalString(_:_:_:_:)CFStringGetPascalStringPtr(_:_:)CFStringGetRangeOfComposedCharactersAtIndex(_:_:)CFStringInitInlineBuffer(_:_:_:)