How do you find the unicode value of a character in Julia?
You can also just do:
julia> Int('a')
97
If you have a String:
julia> s="hello";
julia> Int(s[1])
104
julia> Int(s[2])
101
julia> Int(s[5])
111
More details here.
I think you're looking for codepoint
. From the documentation:
codepoint(c::AbstractChar) -> Integer
Return the Unicode codepoint (an unsigned integer) corresponding to the character
c
(or throw an exception if c does not represent a valid character). ForChar
, this is aUInt32
value, butAbstractChar
types that represent only a subset of Unicode may return a different-sized integer (e.g.UInt8
).
For example:
julia> codepoint('a')
0x00000061
To get the exact equivalent of Python's ord
function, you might want to convert the result to a signed integer:
julia> Int(codepoint('a'))
97