2

As stated in Apple Docs:

An arbitrary Unicode scalar, written as \u{n}, where n is a 1–8 digit hexadecimal number with a value equal to a valid Unicode code point

let dollarSign = "\u{24}" // $, Unicode scalar U+0024

my question is if I have the hexadecimal digit how could I turn it into string. So if I have the following :

let dollarSignHex = 24

How can I map it to let dollarSignString = ????

1 Answer 1

3

24 is a decimal integer constant. If you want the Unicode code point with the hexadecimal number 24 then you have to start with

let dollarCode = 0x24 

or

let dollarCode = 36

Then you can create a string from that integer value with

let dollarSignString = String(UnicodeScalar(dollarCode)) // $

Alternatively, start with a string containing the hexadecimal representation of the code point, and convert that to a number and then to a string:

let dollarSignHex = "24"
let dollarCode = UInt32(dollarSignHex, radix: 16)! // 36
let dollarSignString = String(UnicodeScalar(dollarCode)) // $
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.