String to tuple

Christian S chsu79@REDACTED
Fri Jun 30 11:45:07 CEST 2006


26> A="{aa, bb}.".
"{aa, bb}."
27> B={aa, bb}.
{aa,bb}
28> {ok, Tokens, _} = erl_scan:string(A).
{ok,[{'{',1},{atom,1,aa},{',',1},{atom,1,bb},{'}',1},{dot,1}],1}
29> {ok, B} = erl_parse:parse_term(Tokens).
{ok,{aa,bb}}

Notice how I terminated your string with a dot to make the expression
grammatically sound for the parser.

If you have the data in a file then file:consult/1 is very handy.

On 6/30/06, paul <pghollis@REDACTED> wrote:
> Hi,
>
> I'm trying to convert a string in to a tuple, or a list of tuples.  Eg.
> From:
> A="{aa, bb}".
> to:
> B={aa, bb}.
>
> Any ideas?
>
> Regards Paul.
>



More information about the erlang-questions mailing list