Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
3
Task/String-matching/Tcl/string-matching-1.tcl
Normal file
3
Task/String-matching/Tcl/string-matching-1.tcl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
set isPrefix [string equal -length [string length $needle] $haystack $needle]
|
||||
set isContained [expr {[string first $needle $haystack] >= 0}]
|
||||
set isSuffix [string equal $needle [string range $haystack end-[expr {[string length $needle]-1}] end]]
|
||||
3
Task/String-matching/Tcl/string-matching-2.tcl
Normal file
3
Task/String-matching/Tcl/string-matching-2.tcl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
set isPrefix [string match $needle* $haystack]
|
||||
set isContained [string match *$needle* $haystack]
|
||||
set isSuffix [string match *$needle $haystack]
|
||||
1
Task/String-matching/Tcl/string-matching-3.tcl
Normal file
1
Task/String-matching/Tcl/string-matching-3.tcl
Normal file
|
|
@ -0,0 +1 @@
|
|||
set isContained [regexp ***=$needle $haystack]
|
||||
12
Task/String-matching/Tcl/string-matching-4.tcl
Normal file
12
Task/String-matching/Tcl/string-matching-4.tcl
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
set matchLocations [regexp -indices -all -inline ***=$needle $haystack]
|
||||
# Each match location is a pair, being the index into the string where the needle started
|
||||
# to match and the index where the needle finished matching
|
||||
|
||||
set isContained [expr {[llength $matchLocations] > 0}]
|
||||
set isPrefix [expr {[lindex $matchLocations 0 0] == 0}]
|
||||
set isSuffix [expr {[lindex $matchLocations end 1] == [string length $haystack]-1}]
|
||||
set firstMatchStart [lindex $matchLocations 0 0]
|
||||
puts "Found \"$needle\" in \"$haystack\" at $firstMatchStart"
|
||||
foreach location $matchLocations {
|
||||
puts "needle matched at index [lindex $location 0]"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue