none
Kent Boortz
kent@REDACTED
Mon Sep 16 17:32:30 CEST 2002
fjburgos@REDACTED (Fco Javier Burgos Maciá) writes:
> Is made in erlang any function to convert a term to a string representation?
>
> The term can be a tuple, a tuple of lists, a list of tuples of strings or atoms ...
>
> I have tried to make it using the module io_lib, but I have problems like this:
>
> 1> String=io_lib:fwrite("~p",[{atom1,[{1,2,[atom_2,"string"]}]}]).
> [[123,
> ["atom1",
> 44,
> [91,[[123,["1",44,"2",44,[91,["atom_2",44,"\"string\""],93]],125]],93]],
> 125]]
> 2> String.
> [[123,
> ["atom1",
> 44,
> [91,[[123,["1",44,"2",44,[91,["atom_2",44,"\"string\""],93]],125]],93]],
> 125]]
>
> In this case, I want to obtain "{atom1,[{1,2,[atom_2,"string"]}]}"
The resulting string above is a "deep list", see the beginning and the
first example at
http://www.erlang.org/doc/r8b/lib/stdlib-1.10.1.1/doc/html/io_lib.html
Use something like
1> DeepString = io_lib:fwrite("~p",[{atom1,[{1,2,[atom_2,"string"]}]}]).
2> String = lists:flatten(DeepString).
or directly like
1> String = lists:flatten(io_lib:fwrite("~p",[{atom1,[{1,2,[atom_2,"string"]}]}])).
kent
More information about the erlang-questions
mailing list