如何从列表中捕获单词并使用Erlang返回True
我是Erlang的新手,所以这个例子解释了我在寻找什么
catch_word(msg) ->
Bad = ["BadWord1", "BadWord2"],
case Bad in msg of
true ->
true;
false ->
false
end.
catch_word("Hello, How are u BadWord1").
我该怎么做?
答案 0 :(得分:0)
欢迎来到Erlang,你可能想试试这个:
-export([catch_word/2]).
catch_word(Msg,BadWords)->
catch_word(Msg,BadWords,0).
catch_word(Msg,[],0)->
false;
catch_word(Msg,[Word|BadWords],0)->
catch_word(Msg,BadWords,string:str(Msg,Word));
catch_word(_,_,N)->
true.
和
your_module:catch_word("Hello, How are u BadWord1",["BadWord1", "BadWord2"]).