erlang how to print unicode strings? -


i use io:format log messages disk. each message looks [{field1, content1}, {field2, content2}, ...].

when use io:format("~p", [msg]) print it, file [{field1, <<123,456,789,...>>}, ...].

but want print unicode strings in original form, not integer arrays. should do?

butter71 right won't able print out term , have binaries interpreted unicode. have isolate binaries first. when printing binaries, you'll need use 't' allow print characters outside latin1 range. see: http://www.erlang.org/doc/man/io_lib.html#format-2

here example of printing out have. use unicode:characters_to_binary convert input utf8. doing <<"¿,©,ō">> cause exception.

msg = [{field1, unicode:characters_to_binary("¿,©,ō")}, {field2, ...}, ...] [{field1, field1}|_] = msg. io:format("~ts~n", [field1]). ¿,©,ō ok io:format("~s~n", [field1]).  ¿,©,Å ok 

as can see example without 't' produces garbled text.

if you're going try , walk through structure convert string , print out, @ iolists.


Comments