8

Is there a way how to convert a tuple to a string ?

Consider I have the following list :

[{atom,5,program},{atom,5,receiving},{nil,5}]

I wish to convert this into the following string:

"{atom,5,program},{atom,5,receiving},{nil,5}"

I have tried using erlang:tuple_to_list on each element in the list, which returns

A = [atom,5,program]

Eventually, I can't concatenate that with "{" ++ A ++ "}"

Any ideas how I can turn that to a string ?

cgval
  • 1,096
  • 5
  • 14
  • 31
  • 2
    the answer looks to be there http://stackoverflow.com/questions/9423488/convert-erlang-terms-to-string-or-decode-erlang-binary – Pascal Mar 20 '13 at 21:23

1 Answers1

15
Term = [{atom,5,program},{atom,5,receiving},{nil,5}].
lists:flatten(io_lib:format("~p", [Term])).
Roberto Aloi
  • 30,570
  • 21
  • 75
  • 112
  • if lists:flatten(io_lib:format("~p", [Term])) returns multiline string then use "~999p" for otp <21 and use "~0p" for 21 – tumbudu Mar 12 '19 at 10:59