Consider this variable
X = "1_2_3_4",
How to I get X into a binary string format?
So like this
<<"1_2_3_4">>
I'm getting all manner of errors trying to figure it out.
Thanks in advance, Snelly.
Use the built in conversion function.
list_to_binary(X).
<< <<X/utf8>> || X <- L >>.Thanks Dave! I had a quite a complex function concatinating variables and strings/integers/atoms etc.
In case you are interested:
convert(L) ->
convert(L, <<>>).
convert([], Bin) ->
Bin;
convert([H|T], Bin) ->
convert(T, <<Bin/binary, H>>).
(what I was thinking of as Strings) as lists! Confusing
I think the reason that it's confusing is because sometimes the shell prints out a list as a string and sometimes it doesn't. In my opinion, things would be much clearer if the shell always output a list as a list unless you specifically requested a string.
<< <<X>> || X <- L >> does just what your convert/1 does.[H|convert(Tail)] but not <<H, convert(Tail)>>? Does it have to do with the way binaries are optimized?<<H, (convert(Tail))/bytes>> but note that your version is far more efficient. Try it and check it.