% Note the '.' at the end of the expression inside string.
% The string has to be a valid expression terminated by a '.'.
1> Str = "{\"x\",\"y\"}.".
"{\"x\",\"y\"}."
2> {ok, Ts, _} = erl_scan:string(Str).
{ok,[{'{',1},
{string,1,"x"},
{',',1},
{string,1,"y"},
{'}',1},
{dot,1}],
1}
3> {ok, Tup} = erl_parse:parse_term(Ts).
{ok,{"x","y"}}
4> Tup.
{"x","y"}
1条答案
按热度按时间izkcnapc1#
您应该使用erl_scan模块将字符串标记化,并使用erl_parse将标记转换为Erlang术语。