Erlang:从列表中抓住单词

时间:2016-03-10 14:41:50

标签: erl

如何从列表中捕获单词并使用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").

我该怎么做?

1 个答案:

答案 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"]).