假设我想从列表中获得所有5个字母的单词。
set words {apple banana grape pear peach}
lmap word $words {if {[string length $word] == 5} {expr {"$word"}} else continue}
# ==> apple grape peach
我对的乱七八糟的报价不满意expr {"$word"}
。我希望这可以工作:
lmap word $words {if {[string length $word] == 5} {return $word} else continue}
# ==> apple
从lmap主体“返回”字符串的一种优雅方法是什么?
主要选择是使用set
还是使用string cat
(假设您是最新的)。为了清楚起见,我将以下示例分成多行:
lmap word $words {
if {[string length $word] != 5} {
continue
};
set word
}
lmap word $words {
if {[string length $word] == 5} {
# Requires 8.6.3 or later
string cat $word
} else {
continue
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句