Nếu bạn muốn nhập biểu thức ở trên trong erlang shell
, vui lòng đọc hướng dẫn sử dụng mô-đun unicode
. Chức năng character_to_binary
và character_to_list
là cả hai chức năng có thể đảo ngược. Sau đây là một ví dụ:
([email protected])37> io:getopts().
[{expand_fun,#Fun<group.0.33302583>},
{echo,true},
{binary,false},
{encoding,unicode}]
([email protected])40> A = unicode:characters_to_binary("上海").
<<228,184,138,230,181,183>>
([email protected])41> unicode:characters_to_list(A).
[19978,28023]
([email protected])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]])
([email protected])46> io:format("~ts~n",[ unicode:characters_to_list(A,utf8)]).
上海
ok
Nếu bạn muốn sử dụng unicode:characters_to_binary("上海").
trực tiếp trong mã nguồn, nó là phức tạp hơn một chút. Bạn có thể thử trước tiên để tìm sự khác biệt.
Nguồn
2012-05-15 08:31:26
Đây có phải là sự trợ giúp nào không: http://www.erlang.org/doc/apps/stdlib/unicode_usage.html – NPE