📜  tcl 检查列表中是否存在值 - 无论代码示例

📅  最后修改于: 2022-03-11 15:00:45.481000             🧑  作者: Mango

代码示例1
# Make List object
set List_to_Search [list 1 2 3 4 5 6 7 8 9];
# Identify item to search for:
set findMe 7;
# Search List using lsearch, returns index of first occurrence found
set index [lsearch $List_to_Search $findMe];
# > 6
puts "$findMe = [lindex $List_to_Search $index]";
# If object isn't contained in list - returns '-1' as index:
set notFound [lsearch $List_to_Search 99];
puts "99 not found in List;  $notFound";