搜索字符串存在于列表中

时间:2016-12-24 03:18:23

标签: tcl

如何搜索列表中存在的每个字符串。

set Listing [list AB ZS FR WQ GY GT DA PP YT PW]
set strings {ZS RW DA PW}

if { in each $strings no exists in the $listing} {
    lappend strNoExitst $get
}

提前致谢!

1 个答案:

答案 0 :(得分:2)

set Listing [list AB ZS FR WQ GY GT DA PP YT PW]
set strings {ZS RW DA PW}

set in_list {}
set not_in_list {}

foreach string $strings {
    if {$string in $Listing} {
        lappend in_list $string
    } else {
        lappend not_in_list $string
    }
}

文档: foreachifin (operator)lappendset