2

How can I catch word from list and return True in Erlang?

catch_word(msg) ->
    Bad = ["BadWord1", "BadWord2"],
    case Bad in msg of
        true ->
            true;
        false ->
            false
    end.

catch_word("Hello, How are u BadWord1").
2240
  • 1,547
  • 2
  • 12
  • 30
deounix
  • 141
  • 2
  • 4
  • 18

1 Answers1

1

Welcome to Erlang, you may want to try this:

-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.

and

your_module:catch_word("Hello, How are u BadWord1",["BadWord1", "BadWord2"]).
Cavet
  • 152
  • 8