Character codes: Difference between revisions

added swift
m (Added bc to list of omissions)
(added swift)
Line 1,106:
<lang sml>print (Int.toString (ord #"a") ^ "\n"); (* prints "97" *)
print (Char.toString (chr 97) ^ "\n"); (* prints "a" *)</lang>
 
=={{header|Swift}}==
The type that represent a Unicode code point is <code>UnicodeScalar</code>. You can initialize it with a string literal:
<lang swift>let c1: UnicodeScalar = "a"
println(c1.value) // prints "97"
let c2: UnicodeScalar = "π"
println(c2.value) // prints "960"</lang>
Or, you can get it by iterating a string's unicode scalars view:
<lang swift>let s1 = "a"
for c in s1.unicodeScalars {
println(c.value) // prints "97"
}
let s2 = "π"
for c in s2.unicodeScalars {
println(c.value) // prints "960"
}</lang>
 
You can also initialize it from a <code>UInt32</code> integer:
<lang swift>let i1: UInt32 = 97
println(UnicodeScalar(i1)) // prints "a"
let i2: UInt32 = 960
println(UnicodeScalar(i2)) // prints "π"</lang>
 
=={{header|Tcl}}==
Anonymous user