【发布时间】:2017-09-20 00:10:31
【问题描述】:
我正在尝试查找某些字符串是否真的在列表中。有我的代码:
comparing() ->
FileName = "msg-0001",
{ok,[NumLine],_} = io_lib:fread("msg-~d",FileName),
io:format("Numline:~p~n", [NumLine]),
{ok, Pars} = file:read_file("parsing.txt"),
{ok, Dump} = file:read_file("msg-0001"),
StringNumline = lists:flatten(io_lib:format("~p", [NumLine])),
io:format("StringNumline:~p~n", [StringNumline]),
StringDump = lists:flatten(io_lib:format("~p", [Dump])),
io:format("StringDump:~p~n", [StringDump]),
SubStringDump = string:substr(StringDump, 4),
io:format("SubStringDump:~p~n", [SubStringDump]),
Ndump = concat(StringNumline, SubStringDump),
io:format("Ndump:~p~n", [Ndump]),
FineDump = Ndump--"\">>",
io:format("FineDump:~p~n", [FineDump]),
L1 = binary:split(Pars, <<"\r\n">>, [global]),
io:format("L1=~p~n", [L1]),
Check = lists:member(FineDump, L1),
io:format("Check=~p~n", [Check]),
if
Check ->
file:write_file("check.txt", "true\n", [append]);
true ->
file:write_file("check.txt", "false\n", [append])
end.
这是代码的输出:
10> c(compare).
{ok,compare}
11> compare:comparing().
Numline:1
StringNumline:"1"
StringDump:"<<\"hello\">>"
SubStringDump:"hello\">>"
Ndump:"1hello\">>"
FineDump:"1hello"
L1=[<<"0hello">>,<<"something">>,<<"anyword">>,<<"1hello">>,<<"2exercise">>,
<<"2solution">>,<<"3test">>,<<"new">>,<<"4check">>,<<"4grade">>]
Check=false
ok
我在Check = lists:member(FineDump, L1) 行有问题。尽管 1hello 是列表的成员,但它总是错误的。我不知道哪里错了。它是函数列表:这个操作的成员吗?或者是否存在其他方法来查找字符串是否是列表的成员?我是 Erlang 的新手。
【问题讨论】: