Swift: How to get string from ASCII-Code

YourMJK picture YourMJK · Jun 22, 2014 · Viewed 32.5k times · Source

How can I get a character from a ASCII-Code in Apple's new Swift?

For example 65 returns "A"

Answer

Martin R picture Martin R · Jun 22, 2014

As a character:

let c = Character(UnicodeScalar(65))

Or as a string:

let s = String(UnicodeScalar(UInt8(65)))

Or another way as a string:

let s = "\u{41}"

(Note that the \u escape sequence is in hexadecimal, not decimal)