Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Julia中找到字符的unicode值?_Julia - Fatal编程技术网

如何在Julia中找到字符的unicode值?

如何在Julia中找到字符的unicode值?,julia,Julia,我正在为Julia寻找类似Python的ord(char)的东西,它返回一个整数。我想您正在寻找。从文件中: codepoint(c::AbstractChar)->Integer 返回与字符c对应的Unicode码点(无符号整数)(如果c不代表有效字符,则引发异常)。对于Char,这是一个UInt32值,但仅表示Unicode子集的AbstractChar类型可能返回不同大小的整数(例如UInt8) 例如: julia> codepoint('a') 0x00000061 要获得与Py

我正在为Julia寻找类似Python的
ord(char)
的东西,它返回一个整数。

我想您正在寻找。从文件中:

codepoint(c::AbstractChar)->Integer

返回与字符
c
对应的Unicode码点(无符号整数)(如果c不代表有效字符,则引发异常)。对于
Char
,这是一个
UInt32
值,但仅表示Unicode子集的
AbstractChar
类型可能返回不同大小的整数(例如
UInt8

例如:

julia> codepoint('a')
0x00000061
要获得与Python的
ord
函数完全等效的函数,您可能需要将结果转换为带符号整数:

julia> Int(codepoint('a'))
97
你也可以这样做:

julia> Int('a')
97
如果您有一个字符串:

julia> s="hello";

julia> Int(s[1])
104

julia> Int(s[2])
101

julia> Int(s[5])
111

更多详细信息。

@Asadefa好的,但是对于更古老、更流行的语言,这个问题已经被多次询问、回答和存档。这是朱丽亚(8YS),不是C(48 y)或C++(35y)。我很难理解为什么会发布这条评论。我只想指出这里建议的
Int('a')
Int(codepoint('a'))
完全相同,而且更短。