In Erlang how to I convert a String to a binary value?
+8
A:
Strings are lists of integers in erlang, and therefore you can use the list_to_binary
BIF:
1> list_to_binary("hello world").
<<"hello world">>
tux21b
2010-02-15 20:56:20
Thanks. My brain wasn't working and I kept doing "string_to_binary" in a desperate attempt to prove the documentation, google, and common sense wrong. :)
Zubair
2010-02-15 21:00:42
I also enter `string_to_binary` quite often, but the compiler keeps remaining me that there isn't such a thing ;)
tux21b
2010-02-15 21:04:41
You will also want to keep in mind what happens when the string contains non-ASCII characters. Some function from the `unicode` module might be more appropriate than list_to_binary for such occasions.
ndim
2010-02-22 15:54:29