我有 S1
、S2
和 S3
,我想做一些类似的东西:
如果 S1 != ""且 S2 != ""且 S3 != ""则执行某些操作
。
最佳答案
如果必须全部为空才能执行某些操作,
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.
关于string - 在 Erlang 中如何检查许多字符串是否不为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12065061/