small erlang question.

Peter Lund peter@REDACTED
Thu Jan 15 22:35:11 CET 2004


case string:str(Text,Str1) of
   N when N /=0 -> do_a();
   _ ->
     case string:str(Text,Str2) of
        N2 when N2 /= 0 -> do_b();
        _ -> ....
     end
end

OR:

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

Are two obvious variants.

> 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