如何使用函数搜索列表中的单词,如果列表中的单词则返回true。
示例:
find(string) ->
List = ["bye", "hello", "hi"],
case string in List of
true ->
true;
_ ->
false
end.
find("hi there, how are you today?").
文字是:"你好,今天你好吗?"
它应该在列表中返回true cuz hi。
答案 0 :(得分:1)
1> F = fun(String) -> List = ["bye", "hello", "hi"], lists:any(fun(S) -> lists:member(S, List) end, string:tokens(String, " ,.?!")) end.
#Fun<erl_eval.6.54118792>
2> F("hi, what did you tried so far?").
true