<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
When dealing with strings of text, please do not use <tt>list_to_binary</tt>
or <tt>binary_to_list</tt>, as they only handle lists of bytes
(0..255).<br>
<br>
What you might want instead is <tt>unicode:characters_to_binary(Chars,
InEncoding, OutEncoding)</tt>, where <tt>Chars</tt> can be
either:<br>
<ul>
<li>an iolist (list + binaries of bytes)</li>
<li>a list of codepoints as integers (for Unicode)</li>
<li>a list encoded as latin-1<br>
</li>
<li>binaries encoded as latin-1, utf-8, utf-16 or utf-32</li>
</ul>
<p>And <tt>InEncoding</tt> and <tt>OutEncoding</tt> can be any of:
utf8 (also aliased as unicode), utf16, utf32, and latin1.<br>
</p>
<p>It will generally be safer (especially if you want to deal with
Unicode) to use this function instead of <tt>list_to_binary</tt>,
as it should crash whenever a given character is > 255, which
might happen quite a lot outside of ASCII.<br>
</p>
<p>On 12-05-16 5:00 AM, Ivan Uemlianin wrote:</p>
<blockquote cite="mid:4FB36CAC.2090505@llaisdy.com" type="cite">On
16/05/2012 09:49, Michel Rijnders wrote:
<br>
<blockquote type="cite">Hi,
<br>
<br>
Confused newbie here. Can someone please explain the following:
<br>
<br>
1> <<"foo">>.
<br>
<<"foo">>
<br>
2> Foo = "foo".
<br>
"foo"
<br>
3> <<Foo>>.
<br>
** exception error: bad argument
<br>
<br>
What's the error in the last case?
<br>
<br>
Best,
<br>
Michel
<br>
</blockquote>
<br>
You can use list_to_binary/1 for the same effect:
<br>
<br>
1> <<"foo">>.
<br>
<<"foo">>
<br>
2> Foo = "foo".
<br>
"foo"
<br>
3> list_to_binary(Foo).
<br>
<<"foo">>
<br>
<br>
Ivan
<br>
<br>
<br>
</blockquote>
</body>
</html>