Instance Method


Returns a string representation of the Unicode scalar.


func escaped(asASCII forceASCII: Bool) -> String



Pass true if you need the result to use only ASCII characters; otherwise, pass false.

Return Value

A string representation of the scalar.


Scalar values representing characters that are normally unprintable or that otherwise require escaping are escaped with a backslash.

let tab = Unicode.Scalar(9)
// Prints " "
print(tab.escaped(asASCII: false))
// Prints "\t"

When the forceASCII parameter is true, a Unicode.Scalar instance with a value greater than 127 is represented using an escaped numeric value; otherwise, non-ASCII characters are represented using their typical string value.

let bap = Unicode.Scalar(48165)
print(bap.escaped(asASCII: false))
// Prints "밥"
print(bap.escaped(asASCII: true))
// Prints "\u{BC25}"

See Also

Printing and Displaying a Scalar

var description: String

A textual representation of the Unicode scalar.

func write<Target>(to: inout Target)

Writes the textual representation of the Unicode scalar into the given output stream.

var debugDescription: String

An escaped textual representation of the Unicode scalar, suitable for debugging.

var customMirror: Mirror

A mirror that reflects the Unicode.Scalar instance.

var customPlaygroundQuickLook: _PlaygroundQuickLook

A custom playground Quick Look for the Unicode.Scalar instance.