Search a list: Difference between revisions

Content added Content deleted
(added c#)
(→‎{{header|Tcl}}: corrections)
Line 725: Line 725:
=={{header|Tcl}}==
=={{header|Tcl}}==
<lang tcl>set haystack {Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo}
<lang tcl>set haystack {Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo}
foreach needle {Washington Bush} {
foreach needle {Bush Washington} {
if {[set idx [lsearch $haystack $needle]] == -1} {
if {[set idx [lsearch -exact $haystack $needle]] == -1} {
error "$needle does not appear in the haystack"
error "$needle does not appear in the haystack"
} else {
} else {
Line 734: Line 734:
'''extra credit:'''
'''extra credit:'''
<lang tcl>set haystack {Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo}
<lang tcl>set haystack {Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo}
foreach needle {Washington Bush} {
foreach needle {Bush Washington} {
set indices [lsearch -all $haystack $needle]
set indices [lsearch -all -exact $haystack $needle]
if {[llength $indices] == 0} {
if {[llength $indices] == 0} {
error "$needle does not appear in the haystack"
error "$needle does not appear in the haystack"