escaped(asASCII:)
Returns a string representation of the Unicode scalar.
Declaration
func escaped(asASCII forceASCII: Bool) -> StringParameters
- forceASCII:
Pass
trueif you need the result to use only ASCII characters; otherwise, passfalse.
Return Value
A string representation of the scalar.
Discussion
Scalar values representing characters that are normally unprintable or that otherwise require escaping are escaped with a backslash.
let tab = Unicode.Scalar(9)!
print(tab)
// 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}"