<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFString",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@T@CFStringRef"
  },
  "title" : "CFString"
}
-->

# CFString

```
class CFString
```

## Overview

CFString provides a suite of efficient string-manipulation and string-conversion functions. It offers seamless Unicode support and facilitates the sharing of data between Cocoa and C-based programs. CFString objects are immutable—use [`CFMutableString`](/documentation/CoreFoundation/CFMutableString) to create and manage a string that can be changed after it has been created.

CFString has two primitive functions, [`CFStringGetLength(_:)`](/documentation/CoreFoundation/CFStringGetLength(_:)) and [`CFStringGetCharacterAtIndex(_:_:)`](/documentation/CoreFoundation/CFStringGetCharacterAtIndex(_:_:)), that provide the basis for all other functions in its interface. The `CFStringGetLength` function returns the total number (in terms of UTF-16 code pairs) of characters in the string. The `CFStringGetCharacterAtIndex` function gives access to each character in the string by index, with index values starting at `0`.

CFString provides functions for finding and comparing strings. It also provides functions for reading numeric values from strings, for combining strings in various ways, and for converting a string to different forms (such as encoding and case changes). A number of functions, for example `CFStringFindWithOptions`, allow you to specify a range over which to operate within a string. The specified range must not exceed the length of the string. Debugging options may help you to catch any errors that arise if a range does exceed a string’s length.

Like other Core Foundation types, you can hash CFStrings using the [`CFHash(_:)`](/documentation/CoreFoundation/CFHash(_:)) function. You should never, though, store a hash value outside of your application and expect it to be useful if you read it back in later (hash values may change between different releases of the operating system).

CFString is “toll-free bridged” with its Cocoa Foundation counterpart, <doc://com.apple.documentation/documentation/Foundation/NSString>. This means that the Core Foundation type is interchangeable in function or method calls with the bridged Foundation object. Therefore, in a method where you see an `NSString *` parameter, you can pass in a `CFStringRef`, and in a function where you see a `CFStringRef` parameter, you can pass in an NSString instance. This also applies to concrete subclasses of NSString. See [Toll-Free Bridged Types](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFDesignConcepts/Articles/tollFreeBridgedTypes.html#//apple_ref/doc/uid/TP40010677) for more information on toll-free bridging.

## Topics

### Creating a CFString

[`CFSTR`](/documentation/CoreFoundation/CFSTR)

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

[`CFStringCreateArrayBySeparatingStrings(_:_:_:)`](/documentation/CoreFoundation/CFStringCreateArrayBySeparatingStrings(_:_:_:))

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

[`CFStringCreateByCombiningStrings(_:_:_:)`](/documentation/CoreFoundation/CFStringCreateByCombiningStrings(_:_:_:))

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

[`CFStringCreateCopy(_:_:)`](/documentation/CoreFoundation/CFStringCreateCopy(_:_:))

Creates an immutable copy of a string.

[`CFStringCreateFromExternalRepresentation(_:_:_:)`](/documentation/CoreFoundation/CFStringCreateFromExternalRepresentation(_:_:_:))

Creates a string from its “external representation.”

[`CFStringCreateWithBytes(_:_:_:_:_:)`](/documentation/CoreFoundation/CFStringCreateWithBytes(_:_:_:_:_:))

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

[`CFStringCreateWithBytesNoCopy(_:_:_:_:_:_:)`](/documentation/CoreFoundation/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(_:_:_:)`](/documentation/CoreFoundation/CFStringCreateWithCharacters(_:_:_:))

Creates a string from a buffer of Unicode characters.

[`CFStringCreateWithCharactersNoCopy(_:_:_:_:)`](/documentation/CoreFoundation/CFStringCreateWithCharactersNoCopy(_:_:_:_:))

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

[`CFStringCreateWithCString(_:_:_:)`](/documentation/CoreFoundation/CFStringCreateWithCString(_:_:_:))

Creates an immutable string from a C string.

[`CFStringCreateWithCStringNoCopy(_:_:_:_:)`](/documentation/CoreFoundation/CFStringCreateWithCStringNoCopy(_:_:_:_:))

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

[`CFStringCreateWithFormat`](/documentation/CoreFoundation/CFStringCreateWithFormat)

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

[`CFStringCreateWithFormatAndArguments(_:_:_:_:)`](/documentation/CoreFoundation/CFStringCreateWithFormatAndArguments(_:_:_:_:))

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

[`CFStringCreateWithPascalString(_:_:_:)`](/documentation/CoreFoundation/CFStringCreateWithPascalString(_:_:_:))

Creates an immutable CFString object from a Pascal string.

[`CFStringCreateWithPascalStringNoCopy(_:_:_:_:)`](/documentation/CoreFoundation/CFStringCreateWithPascalStringNoCopy(_:_:_:_:))

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

[`CFStringCreateWithSubstring(_:_:_:)`](/documentation/CoreFoundation/CFStringCreateWithSubstring(_:_:_:))

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

### Searching Strings

[`CFStringCreateArrayWithFindResults(_:_:_:_:_:)`](/documentation/CoreFoundation/CFStringCreateArrayWithFindResults(_:_:_:_:_:))

Searches a string for multiple occurrences of a substring and creates an array of ranges identifying the locations of these substrings within the target string.

[`CFStringFind(_:_:_:)`](/documentation/CoreFoundation/CFStringFind(_:_:_:))

Searches for a substring within a string and, if it is found, yields the range of the substring within the object’s characters.

[`CFStringFindCharacterFromSet(_:_:_:_:_:)`](/documentation/CoreFoundation/CFStringFindCharacterFromSet(_:_:_:_:_:))

Query the range of the first character contained in the specified character set.

[`CFStringFindWithOptions(_:_:_:_:_:)`](/documentation/CoreFoundation/CFStringFindWithOptions(_:_:_:_:_:))

Searches for a substring within a range of the characters represented by a string and, if the substring is found, returns its range within the object’s characters.

[`CFStringFindWithOptionsAndLocale(_:_:_:_:_:_:)`](/documentation/CoreFoundation/CFStringFindWithOptionsAndLocale(_:_:_:_:_:_:))

Returns a Boolean value that indicates whether a given string was found in a given source string.

[`CFStringGetLineBounds(_:_:_:_:_:)`](/documentation/CoreFoundation/CFStringGetLineBounds(_:_:_:_:_:))

Given a range of characters in a string, obtains the line bounds—that is, the indexes of the first character and the final characters of the lines containing the range.

### Comparing Strings

[`CFStringCompare(_:_:_:)`](/documentation/CoreFoundation/CFStringCompare(_:_:_:))

Compares one string with another string.

[`CFStringCompareWithOptions(_:_:_:_:)`](/documentation/CoreFoundation/CFStringCompareWithOptions(_:_:_:_:))

Compares a range of the characters in one string with that of another string.

[`CFStringCompareWithOptionsAndLocale(_:_:_:_:_:)`](/documentation/CoreFoundation/CFStringCompareWithOptionsAndLocale(_:_:_:_:_:))

Compares a range of the characters in one string with another string using a given locale.

[`CFStringHasPrefix(_:_:)`](/documentation/CoreFoundation/CFStringHasPrefix(_:_:))

Determines if the character data of a string begin with a specified sequence of characters.

[`CFStringHasSuffix(_:_:)`](/documentation/CoreFoundation/CFStringHasSuffix(_:_:))

Determines if a string ends with a specified sequence of characters.

### Accessing Characters

[`CFStringCreateExternalRepresentation(_:_:_:_:)`](/documentation/CoreFoundation/CFStringCreateExternalRepresentation(_:_:_:_:))

Creates an “external representation” of a CFString object, that is, a CFData object.

[`CFStringGetBytes(_:_:_:_:_:_:_:_:)`](/documentation/CoreFoundation/CFStringGetBytes(_:_:_:_:_:_:_:_:))

Fetches a range of the characters from a string into a byte buffer after converting the characters to a specified encoding.

[`CFStringGetCharacterAtIndex(_:_:)`](/documentation/CoreFoundation/CFStringGetCharacterAtIndex(_:_:))

Returns the Unicode character at a specified location in a string.

[`CFStringGetCharacters(_:_:_:)`](/documentation/CoreFoundation/CFStringGetCharacters(_:_:_:))

Copies a range of the Unicode characters from a string to a user-provided buffer.

[`CFStringGetCharactersPtr(_:)`](/documentation/CoreFoundation/CFStringGetCharactersPtr(_:))

Quickly obtains a pointer to the contents of a string as a buffer of Unicode characters.

[`CFStringGetCharacterFromInlineBuffer(_:_:)`](/documentation/CoreFoundation/CFStringGetCharacterFromInlineBuffer(_:_:))

Returns the Unicode character at a specific location in an in-line buffer.

[`CFStringGetCString(_:_:_:_:)`](/documentation/CoreFoundation/CFStringGetCString(_:_:_:_:))

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

[`CFStringGetCStringPtr(_:_:)`](/documentation/CoreFoundation/CFStringGetCStringPtr(_:_:))

Quickly obtains a pointer to a C-string buffer containing the characters of a string in a given encoding.

[`CFStringGetLength(_:)`](/documentation/CoreFoundation/CFStringGetLength(_:))

Returns the number (in terms of UTF-16 code pairs) of Unicode characters in a string.

[`CFStringGetPascalString(_:_:_:_:)`](/documentation/CoreFoundation/CFStringGetPascalString(_:_:_:_:))

Copies the character contents of a CFString object to a local Pascal string buffer after converting the characters to a requested encoding.

[`CFStringGetPascalStringPtr(_:_:)`](/documentation/CoreFoundation/CFStringGetPascalStringPtr(_:_:))

Quickly obtains a pointer to a Pascal buffer containing the characters of a string in a given encoding.

[`CFStringGetRangeOfComposedCharactersAtIndex(_:_:)`](/documentation/CoreFoundation/CFStringGetRangeOfComposedCharactersAtIndex(_:_:))

Returns the range of the composed character sequence at a specified index.

[`CFStringInitInlineBuffer(_:_:_:)`](/documentation/CoreFoundation/CFStringInitInlineBuffer(_:_:_:))

Initializes an in-line buffer to use for efficient access of a CFString object’s characters.

### Working With Hyphenation

[`CFStringGetHyphenationLocationBeforeIndex(_:_:_:_:_:_:)`](/documentation/CoreFoundation/CFStringGetHyphenationLocationBeforeIndex(_:_:_:_:_:_:))

Retrieve the first potential hyphenation location found before the specified location.

[`CFStringIsHyphenationAvailableForLocale(_:)`](/documentation/CoreFoundation/CFStringIsHyphenationAvailableForLocale(_:))

Returns a Boolean value that indicates whether hyphenation data is available.

### Working With Encodings

[`CFStringConvertEncodingToIANACharSetName(_:)`](/documentation/CoreFoundation/CFStringConvertEncodingToIANACharSetName(_:))

Returns the name of the IANA registry “charset” that is the closest mapping to a specified string encoding.

[`CFStringConvertEncodingToNSStringEncoding(_:)`](/documentation/CoreFoundation/CFStringConvertEncodingToNSStringEncoding(_:))

Returns the Cocoa encoding constant that maps most closely to a given Core Foundation encoding constant.

[`CFStringConvertEncodingToWindowsCodepage(_:)`](/documentation/CoreFoundation/CFStringConvertEncodingToWindowsCodepage(_:))

Returns the Windows codepage identifier that maps most closely to a given Core Foundation encoding constant.

[`CFStringConvertIANACharSetNameToEncoding(_:)`](/documentation/CoreFoundation/CFStringConvertIANACharSetNameToEncoding(_:))

Returns the Core Foundation encoding constant that is the closest mapping to a given IANA registry “charset” name.

[`CFStringConvertNSStringEncodingToEncoding(_:)`](/documentation/CoreFoundation/CFStringConvertNSStringEncodingToEncoding(_:))

Returns the Core Foundation encoding constant that is the closest mapping to a given Cocoa encoding.

[`CFStringConvertWindowsCodepageToEncoding(_:)`](/documentation/CoreFoundation/CFStringConvertWindowsCodepageToEncoding(_:))

Returns the Core Foundation encoding constant that is the closest mapping to a given Windows codepage identifier.

[`CFStringGetFastestEncoding(_:)`](/documentation/CoreFoundation/CFStringGetFastestEncoding(_:))

Returns for a CFString object the character encoding that requires the least conversion time.

[`CFStringGetListOfAvailableEncodings()`](/documentation/CoreFoundation/CFStringGetListOfAvailableEncodings())

Returns a pointer to a list of string encodings supported by the current system.

[`CFStringGetMaximumSizeForEncoding(_:_:)`](/documentation/CoreFoundation/CFStringGetMaximumSizeForEncoding(_:_:))

Returns the maximum number of bytes a string of a specified length (in Unicode characters) will take up if encoded in a specified encoding.

[`CFStringGetMostCompatibleMacStringEncoding(_:)`](/documentation/CoreFoundation/CFStringGetMostCompatibleMacStringEncoding(_:))

Returns the most compatible Mac OS script value for the given input encoding.

[`CFStringGetNameOfEncoding(_:)`](/documentation/CoreFoundation/CFStringGetNameOfEncoding(_:))

Returns the canonical name of a specified string encoding.

[`CFStringGetSmallestEncoding(_:)`](/documentation/CoreFoundation/CFStringGetSmallestEncoding(_:))

Returns the smallest encoding on the current system for the character contents of a string.

[`CFStringGetSystemEncoding()`](/documentation/CoreFoundation/CFStringGetSystemEncoding())

Returns the default encoding used by the operating system when it creates strings.

[`CFStringIsEncodingAvailable(_:)`](/documentation/CoreFoundation/CFStringIsEncodingAvailable(_:))

Determines whether a given Core Foundation string encoding is available on the current system.

### Getting Numeric Values

[`CFStringGetDoubleValue(_:)`](/documentation/CoreFoundation/CFStringGetDoubleValue(_:))

Returns the primary `double` value represented by a string.

[`CFStringGetIntValue(_:)`](/documentation/CoreFoundation/CFStringGetIntValue(_:))

Returns the integer value represented by a string.

### Getting String Properties

[`CFShowStr(_:)`](/documentation/CoreFoundation/CFShowStr(_:))

Prints the attributes of a string during debugging.

[`CFStringGetTypeID()`](/documentation/CoreFoundation/CFStringGetTypeID())

Returns the type identifier for the CFString opaque type.

### String File System Representations

[`CFStringCreateWithFileSystemRepresentation(_:_:)`](/documentation/CoreFoundation/CFStringCreateWithFileSystemRepresentation(_:_:))

Creates a CFString from a zero-terminated POSIX file system representation.

[`CFStringGetFileSystemRepresentation(_:_:_:)`](/documentation/CoreFoundation/CFStringGetFileSystemRepresentation(_:_:_:))

Extracts the contents of a string as a `NULL`-terminated 8-bit string appropriate for passing to POSIX APIs.

[`CFStringGetMaximumSizeOfFileSystemRepresentation(_:)`](/documentation/CoreFoundation/CFStringGetMaximumSizeOfFileSystemRepresentation(_:))

Determines the upper bound on the number of bytes required to hold the file system representation of the string.

### Getting Paragraph Bounds

[`CFStringGetParagraphBounds(_:_:_:_:_:)`](/documentation/CoreFoundation/CFStringGetParagraphBounds(_:_:_:_:_:))

Given a range of characters in a string, obtains the paragraph bounds—that is, the indexes of the first character and the final characters of the paragraph(s) containing the range.

### Managing Surrogates

[`CFStringGetLongCharacterForSurrogatePair(_:_:)`](/documentation/CoreFoundation/CFStringGetLongCharacterForSurrogatePair(_:_:))

Returns a UTF-32 character that corresponds to a given pair of UTF-16 surrogate characters.

[`CFStringGetSurrogatePairForLongCharacter(_:_:)`](/documentation/CoreFoundation/CFStringGetSurrogatePairForLongCharacter(_:_:))

Maps a given UTF-32 character to a pair of UTF-16 surrogate characters.

[`CFStringIsSurrogateHighCharacter(_:)`](/documentation/CoreFoundation/CFStringIsSurrogateHighCharacter(_:))

Returns a Boolean value that indicates whether a given character is a high character in a surrogate pair.

[`CFStringIsSurrogateLowCharacter(_:)`](/documentation/CoreFoundation/CFStringIsSurrogateLowCharacter(_:))

Returns a Boolean value that indicates whether a given character is a low character in a surrogate pair.

### Data Types

[`CFStringEncoding`](/documentation/CoreFoundation/CFStringEncoding)

An integer type for constants used to specify supported string encodings in various CFString functions.

[`CFStringEncodings`](/documentation/CoreFoundation/CFStringEncodings)

Index type for constants used to specify external string encodings.

[`CFStringCompareFlags`](/documentation/CoreFoundation/CFStringCompareFlags)

A [`CFOptionFlags`](/documentation/CoreFoundation/CFOptionFlags) type for specifying options for string comparison .

[`CFStringInlineBuffer`](/documentation/CoreFoundation/CFStringInlineBuffer)

Defines the buffer and related fields used for in-line buffer access of characters in CFString objects.

### Constants

[String Comparison Flags](/documentation/CoreFoundation/string-comparison-flags)

Flags that specify how string comparisons are performed.

[`CFStringBuiltInEncodings`](/documentation/CoreFoundation/CFStringBuiltInEncodings)

Encodings that are built-in on all platforms on which macOS runs.

[Invalid String Encoding Flag](/documentation/CoreFoundation/invalid-string-encoding-flag)

Special value returned from functions to indicate a string encoding that is not supported or recognized by CFString.

[External String Encodings](/documentation/CoreFoundation/external-string-encodings)

`CFStringEncoding` constants for encodings that may be supported by CFString.

## See Also

  [Property List Programming Topics for Core Foundation](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFPropertyLists/CFPropertyLists.html#//apple_ref/doc/uid/10000130i)

  [Data Formatting Guide for Core Foundation](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFDataFormatting/Articles/CFDataFormatting.html#//apple_ref/doc/uid/10000176i)

  [String Programming Guide for Core Foundation](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFStrings/introCFStrings.html#//apple_ref/doc/uid/10000131i)



---

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)