Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to output UTF-8 in Erlang shell?

Tags:

erlang

Consider this snippet:

Eshell V5.9.1  (abort with ^G)
1> A="Pamet".
"Pamet"
2> A1="Paměť".
[80,97,109,283,357]

("Paměť" is the Czech word for "memory". I chose it because it contains two characters that Erlang thinks are "unprintable".) IIRC Erlang, having originated in Sweden, assumes that if a character doesn't exist in Latin 1, it is unprintable. Hence, even though I'm running the shell on a modern Linux box where everything is UTF-8, it outputs a list of integers instead of "Paměť".

My question: how to write a UTF-8 string to the screen so it appears as a string of characters, and not a list of integers?

like image 671
smithfarm Avatar asked Aug 09 '12 15:08

smithfarm


1 Answers

Here you'd find some explanations on what's going on and how to do it: http://www.erlang.org/doc/apps/stdlib/unicode_usage.html

Basically, you can check that using something like this:

1> lists:keyfind(encoding, 1, io:getopts()).
{encoding, unicode}
2> io:format("~ts~n",["Paměť"]).
Paměť
ok
3> 
like image 136
Alin Avatar answered Oct 19 '22 12:10

Alin