---
title: OSString
framework: kernel
role: symbol
role_heading: Class
path: kernel/osstring
---

# OSString

OSString wraps a C string in a C++ object for use in Libkern collections.

## Declaration

```occ
class OSString : OSObject
```

## Overview

Overview OSString is a container class for managing arrays of characters. An OSString normally maintains its own character buffer and allows changes, but you can create an "immutable" OSString that references an external C string buffer using the "NoCopy" creator functions. Functions called to change the contents of an immutable OSString will fail. Encodings OSString makes no provisions for different character encodings and assumes that a string is a nul-terminated sequence of single-byte characters. User-space code must either assume an encoding (typically ASCII or UTF-8) or determine it in some other way (such as an IORegistryEntry property). Altering Strings OSString's intended use is as a reference-counted object container for a C string and little more. While OSString provides full access to the underlying C string, it provides little in the way of string object manipulation; there are no append or insert functions, only a set-character function. If you need to manipulate OSStrings, it's generally best to get the C strings, alter them as necessary, and create a new OSString object from the resulting C string. Use Restrictions With very few exceptions in the I/O Kit, all Libkern-based C++ classes, functions, and macros are unsafe to use in a primary interrupt context. Consult the I/O Kit documentation related to primary interrupts for more information. OSString provides no concurrency protection; it's up to the usage context to provide any protection necessary. Some portions of the I/O Kit, such as IORegistryEntry, handle synchronization via defined member functions for setting properties.

## Topics

### Miscellaneous

- [free](kernel/osstring/1808271-free.md)
- [getChar](kernel/osstring/1808273-getchar.md)
- [getCStringNoCopy](kernel/osstring/1808275-getcstringnocopy.md)
- [getLength](kernel/osstring/1808278-getlength.md)
- [initWithCString](kernel/osstring/1808281-initwithcstring.md)
- [initWithCStringNoCopy](kernel/osstring/1808284-initwithcstringnocopy.md)
- [initWithString](kernel/osstring/1808286-initwithstring.md)
- [isEqualTo(const char *)](kernel/osstring/1808288-isequalto.md)
- [isEqualTo(const OSData *)](kernel/osstring/1808292-isequalto.md)
- [isEqualTo(const OSMetaClassBase *)](kernel/osstring/1808295-isequalto.md)
- [isEqualTo(const OSString *)](kernel/osstring/1808297-isequalto.md)
- [serialize](kernel/osstring/1808298-serialize.md)
- [setChar](kernel/osstring/1808300-setchar.md)
- [withCString](kernel/osstring/1808301-withcstring.md)
- [withCStringNoCopy](kernel/osstring/1808304-withcstringnocopy.md)
- [withString](kernel/osstring/1808306-withstring.md)

### Instance Methods

- [free](driverkit/osstring/free.md)
- [getCStringNoCopy](driverkit/osstring/getcstringnocopy.md)
- [getChar](kernel/osstring/1490409-getchar.md)
- [getLength](driverkit/osstring/getlength.md)
- [getMetaClass](kernel/osstring/1490433-getmetaclass.md)
- [initWithCString](kernel/osstring/1490404-initwithcstring.md)
- [initWithCStringNoCopy](kernel/osstring/1490434-initwithcstringnocopy.md)
- [initWithString](kernel/osstring/1490425-initwithstring.md)
- [isEqualTo](driverkit/osstring/isequalto-5paj5.md)
- [isEqualTo](driverkit/osstring/isequalto-1uq1f.md)
- [isEqualTo](driverkit/osstring/isequalto-2rg80.md)
- [isEqualTo](driverkit/osstring/isequalto-712xj.md)
- [serialize](kernel/osstring/1490429-serialize.md)
- [setChar](kernel/osstring/1490414-setchar.md)

### Type Methods

- [withCString](driverkit/osstring/withcstring-4wsql.md)
- [withCString](driverkit/osstring/withcstring-721oh.md)
- [withCStringNoCopy](driverkit/osstring/withcstringnocopy.md)
- [withString](driverkit/osstring/withstring.md)

## Relationships

### Inherits From

- [OSObject](kernel/osobject.md)

## See Also

### Simple Types

- [OSBoolean](kernel/osboolean.md)
- [OSNumber](kernel/osnumber.md)
- [OSData](kernel/osdata.md)
