---
title: CFString
framework: corefoundation
role: symbol
role_heading: Class
path: corefoundation/cfstring
---

# CFString

## Declaration

```swift
class CFString
```

## Overview

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 to create and manage a string that can be changed after it has been created. CFString has two primitive functions, CFStringGetLength(_:) and 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(_:) 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, 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 for more information on toll-free bridging.

## Topics

### Creating a CFString

- [CFStringCreateArrayBySeparatingStrings(_:_:_:)](corefoundation/cfstringcreatearraybyseparatingstrings(_:_:_:).md)
- [CFStringCreateByCombiningStrings(_:_:_:)](corefoundation/cfstringcreatebycombiningstrings(_:_:_:).md)
- [CFStringCreateCopy(_:_:)](corefoundation/cfstringcreatecopy(_:_:).md)
- [CFStringCreateFromExternalRepresentation(_:_:_:)](corefoundation/cfstringcreatefromexternalrepresentation(_:_:_:).md)
- [CFStringCreateWithBytes(_:_:_:_:_:)](corefoundation/cfstringcreatewithbytes(_:_:_:_:_:).md)
- [CFStringCreateWithBytesNoCopy(_:_:_:_:_:_:)](corefoundation/cfstringcreatewithbytesnocopy(_:_:_:_:_:_:).md)
- [CFStringCreateWithCharacters(_:_:_:)](corefoundation/cfstringcreatewithcharacters(_:_:_:).md)
- [CFStringCreateWithCharactersNoCopy(_:_:_:_:)](corefoundation/cfstringcreatewithcharactersnocopy(_:_:_:_:).md)
- [CFStringCreateWithCString(_:_:_:)](corefoundation/cfstringcreatewithcstring(_:_:_:).md)
- [CFStringCreateWithCStringNoCopy(_:_:_:_:)](corefoundation/cfstringcreatewithcstringnocopy(_:_:_:_:).md)
- [CFStringCreateWithFormatAndArguments(_:_:_:_:)](corefoundation/cfstringcreatewithformatandarguments(_:_:_:_:).md)
- [CFStringCreateWithPascalString(_:_:_:)](corefoundation/cfstringcreatewithpascalstring(_:_:_:).md)
- [CFStringCreateWithPascalStringNoCopy(_:_:_:_:)](corefoundation/cfstringcreatewithpascalstringnocopy(_:_:_:_:).md)
- [CFStringCreateWithSubstring(_:_:_:)](corefoundation/cfstringcreatewithsubstring(_:_:_:).md)

### Searching Strings

- [CFStringCreateArrayWithFindResults(_:_:_:_:_:)](corefoundation/cfstringcreatearraywithfindresults(_:_:_:_:_:).md)
- [CFStringFind(_:_:_:)](corefoundation/cfstringfind(_:_:_:).md)
- [CFStringFindCharacterFromSet(_:_:_:_:_:)](corefoundation/cfstringfindcharacterfromset(_:_:_:_:_:).md)
- [CFStringFindWithOptions(_:_:_:_:_:)](corefoundation/cfstringfindwithoptions(_:_:_:_:_:).md)
- [CFStringFindWithOptionsAndLocale(_:_:_:_:_:_:)](corefoundation/cfstringfindwithoptionsandlocale(_:_:_:_:_:_:).md)
- [CFStringGetLineBounds(_:_:_:_:_:)](corefoundation/cfstringgetlinebounds(_:_:_:_:_:).md)

### Comparing Strings

- [CFStringCompare(_:_:_:)](corefoundation/cfstringcompare(_:_:_:).md)
- [CFStringCompareWithOptions(_:_:_:_:)](corefoundation/cfstringcomparewithoptions(_:_:_:_:).md)
- [CFStringCompareWithOptionsAndLocale(_:_:_:_:_:)](corefoundation/cfstringcomparewithoptionsandlocale(_:_:_:_:_:).md)
- [CFStringHasPrefix(_:_:)](corefoundation/cfstringhasprefix(_:_:).md)
- [CFStringHasSuffix(_:_:)](corefoundation/cfstringhassuffix(_:_:).md)

### Accessing Characters

- [CFStringCreateExternalRepresentation(_:_:_:_:)](corefoundation/cfstringcreateexternalrepresentation(_:_:_:_:).md)
- [CFStringGetBytes(_:_:_:_:_:_:_:_:)](corefoundation/cfstringgetbytes(_:_:_:_:_:_:_:_:).md)
- [CFStringGetCharacterAtIndex(_:_:)](corefoundation/cfstringgetcharacteratindex(_:_:).md)
- [CFStringGetCharacters(_:_:_:)](corefoundation/cfstringgetcharacters(_:_:_:).md)
- [CFStringGetCharactersPtr(_:)](corefoundation/cfstringgetcharactersptr(_:).md)
- [CFStringGetCharacterFromInlineBuffer(_:_:)](corefoundation/cfstringgetcharacterfrominlinebuffer(_:_:).md)
- [CFStringGetCString(_:_:_:_:)](corefoundation/cfstringgetcstring(_:_:_:_:).md)
- [CFStringGetCStringPtr(_:_:)](corefoundation/cfstringgetcstringptr(_:_:).md)
- [CFStringGetLength(_:)](corefoundation/cfstringgetlength(_:).md)
- [CFStringGetPascalString(_:_:_:_:)](corefoundation/cfstringgetpascalstring(_:_:_:_:).md)
- [CFStringGetPascalStringPtr(_:_:)](corefoundation/cfstringgetpascalstringptr(_:_:).md)
- [CFStringGetRangeOfComposedCharactersAtIndex(_:_:)](corefoundation/cfstringgetrangeofcomposedcharactersatindex(_:_:).md)
- [CFStringInitInlineBuffer(_:_:_:)](corefoundation/cfstringinitinlinebuffer(_:_:_:).md)

### Working With Hyphenation

- [CFStringGetHyphenationLocationBeforeIndex(_:_:_:_:_:_:)](corefoundation/cfstringgethyphenationlocationbeforeindex(_:_:_:_:_:_:).md)
- [CFStringIsHyphenationAvailableForLocale(_:)](corefoundation/cfstringishyphenationavailableforlocale(_:).md)

### Working With Encodings

- [CFStringConvertEncodingToIANACharSetName(_:)](corefoundation/cfstringconvertencodingtoianacharsetname(_:).md)
- [CFStringConvertEncodingToNSStringEncoding(_:)](corefoundation/cfstringconvertencodingtonsstringencoding(_:).md)
- [CFStringConvertEncodingToWindowsCodepage(_:)](corefoundation/cfstringconvertencodingtowindowscodepage(_:).md)
- [CFStringConvertIANACharSetNameToEncoding(_:)](corefoundation/cfstringconvertianacharsetnametoencoding(_:).md)
- [CFStringConvertNSStringEncodingToEncoding(_:)](corefoundation/cfstringconvertnsstringencodingtoencoding(_:).md)
- [CFStringConvertWindowsCodepageToEncoding(_:)](corefoundation/cfstringconvertwindowscodepagetoencoding(_:).md)
- [CFStringGetFastestEncoding(_:)](corefoundation/cfstringgetfastestencoding(_:).md)
- [CFStringGetListOfAvailableEncodings()](corefoundation/cfstringgetlistofavailableencodings().md)
- [CFStringGetMaximumSizeForEncoding(_:_:)](corefoundation/cfstringgetmaximumsizeforencoding(_:_:).md)
- [CFStringGetMostCompatibleMacStringEncoding(_:)](corefoundation/cfstringgetmostcompatiblemacstringencoding(_:).md)
- [CFStringGetNameOfEncoding(_:)](corefoundation/cfstringgetnameofencoding(_:).md)
- [CFStringGetSmallestEncoding(_:)](corefoundation/cfstringgetsmallestencoding(_:).md)
- [CFStringGetSystemEncoding()](corefoundation/cfstringgetsystemencoding().md)
- [CFStringIsEncodingAvailable(_:)](corefoundation/cfstringisencodingavailable(_:).md)

### Getting Numeric Values

- [CFStringGetDoubleValue(_:)](corefoundation/cfstringgetdoublevalue(_:).md)
- [CFStringGetIntValue(_:)](corefoundation/cfstringgetintvalue(_:).md)

### Getting String Properties

- [CFShowStr(_:)](corefoundation/cfshowstr(_:).md)
- [CFStringGetTypeID()](corefoundation/cfstringgettypeid().md)

### String File System Representations

- [CFStringCreateWithFileSystemRepresentation(_:_:)](corefoundation/cfstringcreatewithfilesystemrepresentation(_:_:).md)
- [CFStringGetFileSystemRepresentation(_:_:_:)](corefoundation/cfstringgetfilesystemrepresentation(_:_:_:).md)
- [CFStringGetMaximumSizeOfFileSystemRepresentation(_:)](corefoundation/cfstringgetmaximumsizeoffilesystemrepresentation(_:).md)

### Getting Paragraph Bounds

- [CFStringGetParagraphBounds(_:_:_:_:_:)](corefoundation/cfstringgetparagraphbounds(_:_:_:_:_:).md)

### Managing Surrogates

- [CFStringGetLongCharacterForSurrogatePair(_:_:)](corefoundation/cfstringgetlongcharacterforsurrogatepair(_:_:).md)
- [CFStringGetSurrogatePairForLongCharacter(_:_:)](corefoundation/cfstringgetsurrogatepairforlongcharacter(_:_:).md)
- [CFStringIsSurrogateHighCharacter(_:)](corefoundation/cfstringissurrogatehighcharacter(_:).md)
- [CFStringIsSurrogateLowCharacter(_:)](corefoundation/cfstringissurrogatelowcharacter(_:).md)

### Data Types

- [CFStringEncoding](corefoundation/cfstringencoding.md)
- [CFStringEncodings](corefoundation/cfstringencodings.md)
- [CFStringCompareFlags](corefoundation/cfstringcompareflags.md)
- [CFStringInlineBuffer](corefoundation/cfstringinlinebuffer.md)

### Constants

- [String Comparison Flags](corefoundation/string-comparison-flags.md)
- [CFStringBuiltInEncodings](corefoundation/cfstringbuiltinencodings.md)
- [Invalid String Encoding Flag](corefoundation/invalid-string-encoding-flag.md)
- [External String Encodings](corefoundation/external-string-encodings.md)

## Relationships

### Inherited By

- [CFMutableString](corefoundation/cfmutablestring.md)

### Conforms To

- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)

## See Also

### Related Documentation

- [Property List Programming Topics for Core Foundation](apple-archive/documentation/CoreFoundation/Conceptual/CFPropertyLists.md)
- [Data Formatting Guide for Core Foundation](apple-archive/documentation/CoreFoundation/Conceptual/CFDataFormatting/Articles/CFDataFormatting.html.md)
- [String Programming Guide for Core Foundation](apple-archive/documentation/CoreFoundation/Conceptual/CFStrings/introCFStrings.html.md)

### Opaque Types

- [CFAllocator](corefoundation/cfallocator.md)
- [CFArray](corefoundation/cfarray.md)
- [CFAttributedString](corefoundation/cfattributedstring.md)
- [CFBag](corefoundation/cfbag.md)
- [CFBinaryHeap](corefoundation/cfbinaryheap.md)
- [CFBitVector](corefoundation/cfbitvector.md)
- [CFBoolean](corefoundation/cfboolean.md)
- [CFBundle](corefoundation/cfbundle.md)
- [CFCalendar](corefoundation/cfcalendar.md)
- [CFCharacterSet](corefoundation/cfcharacterset.md)
- [CFData](corefoundation/cfdata.md)
- [CFDate](corefoundation/cfdate.md)
- [CFDateFormatter](corefoundation/cfdateformatter.md)
- [CFDictionary](corefoundation/cfdictionary.md)
- [CFError](corefoundation/cferror.md)
