Instance Property

asciiValue

The ASCII encoding value of this character, if it is an ASCII character.

Declaration

var asciiValue: UInt8? { get }

Discussion

let chars: [Character] = ["a", " ", "™"]
for ch in chars {
    print(ch, "-->", ch.properties.numericValue)
}
// a --> 97
//   --> 32
// ™ --> nil

A character with the value “\r\n” (CR-LF) is normalized to “\n” (LF) and has an asciiValue property equal to 10.

let cr = "\r" as Character
// cr.asciiValue == 13
let lf = "\n" as Character
// lf.asciiValue == 10
let crlf = "\r\n" as Character
// crlf.asciiValue == 10

See Also

Working with a Character’s Unicode Values

init(Unicode.Scalar)

Creates a character containing the given Unicode scalar value.

var isASCII: Bool

A Boolean value indicating whether this is an ASCII character.