0

What is a syntax for generating the Unicode hexadecimal value of a character in Julia as a String?

To generate the Unicode hexadecimal value of a character <char> as a UInt32, one can execute codepoint('<char>').

Example

julia> codepoint('α')
0x000003b1

2 Answers2

0

The codepoint of a character <char>, in hexadecimal integer representation, as a String type, can be found by string(Int('<char>'), base=16).

Example

julia> string(Int('α'), base=16)
"3b1"
0

Not exactly sure I understand the question. But the following might be relevant:

\u3B1 is a unicode literal character with codepoint 0x3B1. This codepoint is for α. Entering '\u3B1' produces the α in the parsed string.

So perhaps:

julia> string(codepoint('α'); base=16)
"3b1"

could help in writing:

julia> "\\u"*string(codepoint('α'); base=16)
"\\u3b1"

which prints as:

julia> print("\\u"*string(codepoint('α'); base=16))
\u3b1

and can be copy pasted into a string (with the double backslash), which will later be parsed in to α, as shown by:

julia> Meta.parse( "'\\u"*string(codepoint('α'); base=16)*"'")
'α': Unicode U+03B1 (category Ll: Letter, lowercase)
Dan Getz
  • 17,002
  • 2
  • 23
  • 41