Wei Jay Wei Jay - 3 months ago 9
Swift Question

How can I get unicode number of a character?

How can I get the Unicode number of a given string ?

For example, Cyrillic Small Letter Er U+0440 stands for "р"

How can I get "U+0440" or "0440"?



====Technical information====

Unicode number: U+0440

HTML-code: &#1088

var myString = "р"
for scalar in myString.unicodeScalars {
print("\(scalar.value) ") // print: 1008
}

Answer

440 in hex is equal to 1088 in decimal:

var myString = "р"
for scalar in myString.unicodeScalars {
    print(String(scalar.value, radix: 16))
}
Comments