String matching: Difference between revisions

Content added Content deleted
(→‎Tcl: Added implementation)
m (→‎{{header|Tcl}}: Explanatory notes)
Line 93: Line 93:


=={{header|Tcl}}==
=={{header|Tcl}}==
In this code, we are looking in various ways for the string in the variable <tt>needle</tt> in the string in the variable <tt>haystack</tt>.
<lang tcl>set isPrefix [string equal -length [string length $needle] $haystack $needle]
<lang tcl>set isPrefix [string equal -length [string length $needle] $haystack $needle]
set isContained [expr {[string first $needle $haystack] >= 0}]
set isContained [expr {[string first $needle $haystack] >= 0}]