简体   繁体   English

Erlang:从列表中查找单词并返回 True

[英]Erlang: find word from list and return True

How can I make function to search for a word in list and return true if word in list.如何使函数搜索列表中的单词并返回 true 如果列表中的单词。

Example :例子 :

find(string) ->
    List = ["bye", "hello", "hi"],
    case string in List of
        true ->
            true;
        _ ->
            false
    end.

find("hi there, how are you today?").

And the text is : "hi there, How are you today?"文字是:“嗨,你今天好吗?”

it should return true cuz hi in list.它应该在列表中返回 true cuz hi。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM