必须搜索子字符串是否存在于字符串中

Had to search whether the substring are present in the strings or not

我有几个子字符串要在下面的字符串中搜索

These are the substrings "School, Students, Teachers, Classrooms"

下面是字符串我搜索上面的子字符串是否存在于下面的字符串中-

School_Name
Number_Of_Students
Number_Of_Teachers
Number_Of_Classrooms

我试过这种方式,这里的字符串中有 Students、Teachers、Classrooms 子字符串,但我无法正确搜索它

#!/usr/bin/tclsh
set list {School Students Teachers Classrooms}
set string "Number_Of_Students Number_Of_Teachers Number_Of_Classrooms"
if {"$string" in $list} {
puts "$string"
}

谁能帮帮我

in 运算符 将字符串与列表元素进行精确匹配。您可能希望将 lsearchstring match 样式的 glob 模式一起使用;他们很容易合作。或者可能只是 string match 和一些 foreach 循环;我不确定模式列表是什么,搜索列表是什么 space。

# Added extra item to show what happens with multiple matches
set inputs {
    School_Name
    Number_Of_Students
    Number_Of_Teachers
    Number_Of_Classrooms
    Students_Per_School
}
set items {School Students Teachers Classrooms}
foreach input $inputs {
    foreach item $items {
        if {[string match *$item* $input]} {
            puts "found $item in $input"
        }
    }
}