如何将此字符串"[{type,a},{to,room01023123},{body,hey what's up mister},{by,someone}]"
转换为像[{"type","a"},{"to","room01023123"},{"body","hey what's up mister"},{"by","someone"}]
答案 0 :(得分:5)
如果您需要阅读文件,请使用file:consult
-spec consult(Filename) -> {ok, Terms} | {error, Reason}
否则,您可以将erl_parse
模块与erl_scan
结合使用。在最简单的情况下,像这样
{ok, Tokens, _Line} = erl_scan:string("{hello, world}."),
erl_parse:parse_term(Tokens).
不要忘记,条款应以句号结束。