我从文本文件中收到以下字符串列表:
[ “{0988070979,APP03 @媒体}”, “{0988070978,APP01 @媒体}”, “{0988070977,APP02 @媒体}”]
我需要相同的列表但没有引号(“”),如下所示:
[{0988070979,APP03 @媒体},{0988070978,APP01 @媒体},{0988070977,APP02 @媒体}]
答案 0 :(得分:0)
您应该使用erl_scan模块tokenize
字符串和erl_parse将令牌转换为erlang字词。
让你的字符串为Str
{ok, Ts, _} = erl_scan:string(Str).
{ok, Tup} = erl_parse:parse_term(Ts).
Tup
是您需要的元组......
答案 1 :(得分:0)
1> L = ["{0988070979,APP03@media}","{0988070978,APP01@media}","{0988070977,APP02@media}"].
["{0988070979,APP03@media}","{0988070978,APP01@media}",
"{0988070977,APP02@media}"]
2> [{N, M} || X <- L, [N, M] <- [string:tokens(X, "{},")]].
[{"0988070979","APP03@media"},
{"0988070978","APP01@media"},
{"0988070977","APP02@media"}]
或(不推荐)
3> [{list_to_integer(N), list_to_atom(M)} || X <- L, [N, M] <- [string:tokens(X, "{},")]].
[{988070979,'APP03@media'},
{988070978,'APP01@media'},
{988070977,'APP02@media'}]
等等。