---
title: "getCString(_:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsstring/getcstring(_:)"
---

# getCString(_:)

Invokes getCString(_:maxLength:range:remaining:) with NSMaximumStringLength as the maximum length, the receiver’s entire extent as the range, and NULL for the remaining range.

## Declaration

```swift
func getCString(_ bytes: UnsafeMutablePointer<CChar>)
```

## Discussion

Discussion buffer must be large enough to contain the resulting C-string plus a terminating NULL character (which this method adds—[string cStringLength]). Raises an NSCharacterConversionException if the receiver can’t be represented in the default C-string encoding without loss of information. Use canBeConverted(to:) if necessary to check whether a string can be losslessly converted to the default C-string encoding. If it can’t, use lossyCString() or data(using:allowLossyConversion:) to get a C-string representation with some loss of information.

## See Also

### Related Documentation

- [cString(using:)](foundation/nsstring/cstring(using:).md)
- [utf8String](foundation/nsstring/utf8string.md)
- [getCString(_:maxLength:encoding:)](foundation/nsstring/getcstring(_:maxlength:encoding:).md)

### Deprecated

- [string(withCString:)](foundation/nsstring/string(withcstring:).md)
- [init(CString:)](foundation/nsstring/init(cstring:)-vkuo.md)
- [string(withCString:length:)](foundation/nsstring/string(withcstring:length:).md)
- [init(CString:length:)](foundation/nsstring/init(cstring:length:)-5ure3.md)
- [init(CStringNoCopy:length:freeWhenDone:)](foundation/nsstring/init(cstringnocopy:length:freewhendone:)-86dm2.md)
- [string(withContentsOfFile:)](foundation/nsstring/string(withcontentsoffile:).md)
- [init(contentsOfFile:)](foundation/nsstring/init(contentsoffile:).md)
- [string(withContentsOf:)](foundation/nsstring/string(withcontentsof:).md)
- [init(contentsOfURL:)](foundation/nsstring/init(contentsofurl:).md)
- [write(toFile:atomically:)](foundation/nsstring/write(tofile:atomically:).md)
- [write(to:atomically:)](foundation/nsstring/write(to:atomically:).md)
- [getCharacters(_:)](foundation/nsstring/getcharacters(_:).md)
- [cString()](foundation/nsstring/cstring().md)
- [lossyCString()](foundation/nsstring/lossycstring().md)
- [cStringLength()](foundation/nsstring/cstringlength().md)
