[erlang-questions] Is this proper way to convert a latin string to utf8 string

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Sun Jul 26 18:14:16 CEST 2015


On Sun, Jul 26, 2015 at 3:11 PM, 王昊 <jusfeel@REDACTED> wrote:

> Hi,
> Does anyone know if this is a proper way to convert latin string to utf-8
> string?
>
> {ok, S} = asn1rt:utf8_binary_to_list(list_to_binary([232,191,153])).
> io:format("~ts~n",[S]).
>

Use the `unicode` module for character conversion:

1> unicode:characters_to_binary([232,191,153], latin1, utf8).
<<195,168,194,191,194,153>>
2> io:format("~ts~n", [v(1)]).

It prints as three characters:

LATIN SMALL LETTER E WITH GRAVE
INVERTED QUESTION MARK
(unbound 0x0099 part of the Latin-1 supplement range)

I don't know if this is correct for you.

What are you trying to do generally? That is, what is the problem you are
having. Perhaps we can give better help if we know your situation.

-- 
J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150726/cf15fa8c/attachment.htm>


More information about the erlang-questions mailing list