79725075

Date: 2025-08-04 14:55:58
Score: 2.5
Natty:
Report link

.

How can I extract the Unicode code point(s) of a given Character without first converting it to a String?

Use this:

let example: Character = "πŸ‡ΊπŸ‡Έ"

print(getUnicodeHexadecimalCodes(example)) // Prints: ["1F1FA", "1F1F8"]



func getUnicodeHexadecimalCodes(_ theCharacter: Character) -> [String] {
    var dum: [String] = []
    let dummer: String = "%04X" // Basic format string. Others: "U+%04X", or "\\u{%04X}".
    theCharacter.unicodeScalars.forEach { dum.append(String(format: dummer, $0.value)) }
    return dum
}
//
// Or in decimal format:
//
func getUnicodeDecimalCodes(_ character: Character) -> [UInt32] {
    var dum: [UInt32] = []
    character.unicodeScalars.forEach { dum.append($0.value) }
    return dum
}



// 😎

Reasons:
  • Blacklisted phrase (0.5): How can I
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: LGLB