In Erlang how do I convert a String to a binary value?

Viewed 20085

In Erlang how do I convert a string to a binary value?

String = "Hello"
%% should be
Binary = <<"Hello">>
2 Answers

In Erlang strings are represented as a list of integers. You can therefore use the list_to_binary (built-in-function, aka BIF). Here is an example I ran in the Erlang console (started with erl):

1> list_to_binary("hello world").
<<"hello world">>
Related