small erlang question.

Peter Lund <>
Thu Jan 15 22:30:00 CET 2004


case string:str(Text,Str1) of
   0 -> do_a();
   _ ->
     case string:str(Text,Str2) of
        0 -> do_b();

      string:str() of
> if (string:str(Text,String)  /= 0) -> ...;
>    (string:str(Text,String2) /= 0) ->...
> end
>
> but string:str is not accepted in a condition.
>
> I wrote a small function witch takes Text and a list of {Return_value,
> String} which tries each string and return Return_value if it matches:
>
> find_strings(_, []) -> false;
>
> find_strings(Texte,[{Retour,Chaine}|Liste])  ->
>         T1 = string:str(Texte, Chaine),
>         case T1 of
>                 0       -> find_strings(Texte,[Liste]);
>                 _Else   -> Retour
>         end
>         .
>
> but I wanted to know if there was not an other elegant solution that
> does not require a function.
>
> Regards.
>
> Raphaël.






More information about the erlang-questions mailing list