---
title: utf8CString
framework: swift
role: symbol
role_heading: Instance Property
path: swift/string/utf8cstring
---

# utf8CString

A contiguously stored null-terminated UTF-8 representation of the string.

## Declaration

```swift
var utf8CString: ContiguousArray<CChar> { get }
```

## Discussion

Discussion To access the underlying memory, invoke withUnsafeBufferPointer on the array. let s = "Hello!" let bytes = s.utf8CString print(bytes) // Prints "[72, 101, 108, 108, 111, 33, 0]"

bytes.withUnsafeBufferPointer { ptr in     print(strlen(ptr.baseAddress!)) } // Prints "6"

## See Also

### Getting C Strings

- [withCString(_:)](swift/string/withcstring(_:).md)
- [withCString(encodedAs:_:)](swift/string/withcstring(encodedas:_:).md)
