Creates a new string by copying the null-terminated data referenced by the given pointer using the specified encoding.
SDK
- Xcode 8.0+
Framework
- Swift Standard Library
Declaration
Parameters
cString
A pointer to a null-terminated code sequence encoded in
encoding
.encoding
The Unicode encoding of the data referenced by
c
.String isRepairing
Pass
true
to create a new string, even when the data referenced byc
contains ill-formed sequences. Ill-formed sequences are replaced with the Unicode replacement character (String "\u{FFFD}"
). Passfalse
to interrupt the creation of the new string if an ill-formed sequence is detected.
Return Value
A tuple with the new string and a Boolean value that indicates whether any repairs were made. If is
is false
and an ill-formed sequence is detected, this method returns nil
.
Discussion
When you pass true
as is
, this method replaces ill-formed sequences with the Unicode replacement character ("\u{FFFD}"
); otherwise, an ill-formed sequence causes this method to stop decoding and return nil
.
The following example calls this method with pointers to the contents of two different CChar
arrays—the first with well-formed UTF-8 code unit sequences and the second with an ill-formed sequence at the end.