How do you find the unicode value of a character in Julia?

vboreda514 :

I'm looking for something like Python's ord(char) for Julia that returns an integer.

François Févotte :

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). For Char, this is a UInt32 value, but AbstractChar 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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=367766&siteId=1