如何检查Erlang中是否有许多字符串不为空?

2 string erlang conditional

我有S1,S2而且S3,我想做一些像:

if S1 != "" and S2 != "" and S3 != "" then do something.

Muz*_*hua 7

如果所有必须为空,您可以执行某些操作,

case {S1,S2,S3} of
    {[],[],[]} -> %% empty
    _ -> %% not empty
end.
如果你需要知道哪一个是空的
case {S1,S2,S3} of
    {[],[],[]} -> %% empty
    {[],_,_} -> %% S1 empty
    {_,[],_} -> %% S2 empty
    {_,_,[]} -> %% S3 empty
end.
清洁代码!!

编辑
case lists:member(true,[Each =:= []  || Each <- [S1,S2,S3]]) of
    true -> 
        %% atleast one of them is empty
    false -> 
        %% all are not empty
end.

  • 这就是为什么列表:all/2存在的原因. (2认同)
  • @RichardC:是的,就像`lists:all([L == [] || L < - [S1,S2,S3]])`. (2认同)