Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of strings to binary and back again

Tags:

erlang

I've stumbled on a quite irritating problem;

I'm trying to generate a binary of a string-list and back again. Eg

erlang:binary_to_list(erlang:list_to_binary(["hello", "world"])

This will return "helloworld" and not a list with two different elements. Does anyone have any ideas of how to solve this? One solution might be to encode every element, but there might be a more elegant solution for this?

like image 264
Burbas Avatar asked Oct 27 '25 07:10

Burbas


1 Answers

Yes, you have to encode it somehow. Here's the simplest way to do it by encoding it into Erlang binary term format

erlang:binary_to_term(erlang:term_to_binary(["hello", "world"]))
like image 165
gleber Avatar answered Oct 29 '25 07:10

gleber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!