Function

CFStringCreateWithBytes

Creates a string from a buffer containing characters in a specified encoding.

Declaration

CFStringRef CFStringCreateWithBytes(CFAllocatorRef alloc, const UInt8 *bytes, CFIndex numBytes, CFStringEncoding encoding, Boolean isExternalRepresentation);

Parameters

alloc

The allocator to use to allocate memory for the new string. Pass NULL or kCFAllocatorDefault to use the current default allocator.

bytes

A buffer containing characters in the encoding specified by encoding. The buffer must not contain a length byte (as in Pascal buffers) or any terminating NULL character (as in C buffers).

numBytes

The number of bytes in bytes.

encoding

The string encoding of the characters in the buffer.

isExternalRepresentation

true if the characters in the byte buffer are in an “external representation” format—that is, whether the buffer contains a BOM (byte order marker). This is usually the case for bytes that are read in from a text file or received over the network. Otherwise, pass false.

Return Value

An immutable string, or NULL if there was a problem creating the object. Ownership follows the The Create Rule.

Discussion

This function handles character data in an “external representation” format by interpreting any BOM (byte order marker) character and performing any necessary byte swapping.

See Also

Creating a CFString

CFSTR

Creates an immutable string from a constant compile-time string.

CFStringCreateArrayBySeparatingStrings

Creates an array of CFString objects from a single CFString object.

CFStringCreateByCombiningStrings

Creates a single string from the individual CFString objects that comprise the elements of an array.

CFStringCreateCopy

Creates an immutable copy of a string.

CFStringCreateFromExternalRepresentation

Creates a string from its “external representation.”

CFStringCreateWithBytesNoCopy

Creates a string from a buffer, containing characters in a specified encoding, that might serve as the backing store for the new string.

CFStringCreateWithCharacters

Creates a string from a buffer of Unicode characters.

CFStringCreateWithCharactersNoCopy

Creates a string from a buffer of Unicode characters that might serve as the backing store for the object.

CFStringCreateWithCString

Creates an immutable string from a C string.

CFStringCreateWithCStringNoCopy

Creates a CFString object from an external C string buffer that might serve as the backing store for the object.

CFStringCreateWithFormat

Creates an immutable string from a formatted string and a variable number of arguments.

CFStringCreateWithFormatAndArguments

Creates an immutable string from a formatted string and a variable number of arguments (specified in a parameter of type va_list).

CFStringCreateWithPascalString

Creates an immutable CFString object from a Pascal string.

CFStringCreateWithPascalStringNoCopy

Creates a CFString object from an external Pascal string buffer that might serve as the backing store for the object.

CFStringCreateWithSubstring

Creates an immutable string from a segment (substring) of an existing string.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software