Instance Method


Converts the receiver’s content to the default C-string encoding and stores them in a given buffer.


func getCString(_ bytes: UnsafeMutablePointer<Int8>, maxLength: Int, range aRange: NSRange, remaining leftoverRange: NSRangePointer?)


buffer must be large enough to contain maxLength bytes plus a terminating zero character (which this method adds). Copies and converts as many characters as possible from aRange and stores the range of those not converted in the range given by leftoverRange (if it’s non-nil). Raises an NSRangeException if any part of aRange lies beyond the end of the string.

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 Symbols

func cString(using: UInt)

Returns a representation of the receiver as a C string using a given encoding.

var utf8String: UnsafePointer<Int8>?

A null-terminated UTF8 representation of the string.

func getCString(UnsafeMutablePointer<Int8>, maxLength: Int, encoding: UInt)

Converts the receiver’s content to a given encoding and stores them in a buffer.