UTF-8 problem ?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

UTF-8 problem ?

z_axis
This post has NOT been accepted by the mailing list yet.
>uname -a
FreeBSD mybsd.zsoft.com 8.2-RELEASE FreeBSD 8.2-RELEASE #2: Sat Feb 26 16:53:57 CST 2011     root@mybsd.zsoft.com:/media/G/usr/obj/media/G/usr/src/sys/MYKERNEL  i386

>locale
LANG=zh_CN.UTF-8
LC_CTYPE="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"

>date
2011年 4月 6日 星期三 07时56分51秒 CST

>erl
Erlang R14B02 (erts-5.8.3) [source] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.8.3  (abort with ^G)
1> os:cmd("date").
[50,48,49,49,229,185,180,32,52,230,156,136,32,54,230,151,
 165,32,230,152,159,230,156,159,228,184,137,32,48|...]
2>

How can i make erlang display correct date string ?
e^(π.i) + 1 = 0
moi
Reply | Threaded
Open this post in threaded view
|

Re: UTF-8 problem ?

moi
The list from os:cmd is a byte list of UTF-8 string. You can use "~ts" to print it properly.

1> io:format("~ts~n", [unicode:characters_to_list(erlang:iolist_to_binary([50,48,49,49,229,185,180,32,52,230,156,136,32,54,230,151,165]))]).
2011年 4月 6日
ok