如何从列表中捕获单词并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").
如何从列表中捕获单词并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").
欢迎来到 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"]).