Erlang和二进制西里尔 [英] Erlang and binary with cyrillic

查看:114
本文介绍了Erlang和二进制西里尔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够使用二进制与他们西里尔字符。我试着只是写<为code>&LT;&LT;абвгд&GT;方式&gt; ,但我得到了一个错误badarg

I need to be able to use binaries with Cyrillic characters in them. I tried just writing <<"абвгд">> but I got a badarg error.

我如何与西里尔字母(或单向code)字符串在二郎山工作?

How can I work with Cyrillic (or unicode) strings in Erlang?

推荐答案

如果您想输入上图中的前$ P $在二郎壳 pssion,请阅读 UNI code 模块的用户手册。
功能 character_to_binary character_to_list 都是可逆的功能。下面是一个例子:

If you want to input the above expression in erlang shell, please read unicode module user manual. Function character_to_binary, and character_to_list are both reversable function. The following are an example:

(emacs@yus-iMac.local)37> io:getopts().
[{expand_fun,#Fun<group.0.33302583>},
 {echo,true},
 {binary,false},
 {encoding,unicode}]

(emacs@yus-iMac.local)40> A = unicode:characters_to_binary("上海").
<<228,184,138,230,181,183>>

(emacs@yus-iMac.local)41> unicode:characters_to_list(A).
[19978,28023]

(emacs@yus-iMac.local)45> io:format("~s~n",[ unicode:characters_to_list(A,utf8)]).
** exception error: bad argument
     in function  io:format/3
        called as io:format(<0.30.0>,"~s~n",[[19978,28023]])

(emacs@yus-iMac.local)46> io:format("~ts~n",[ unicode:characters_to_list(A,utf8)]).
上海
ok

如果你想使用 UNI code:characters_to_binary(上海)直接在源$ C ​​$ C,这是一个有点复杂。你可以尝试先找到差异。

If you want to use unicode:characters_to_binary("上海"). directly in the source code, it is a little more complex. You can try it firstly to find difference.

这篇关于Erlang和二进制西里尔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆