Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
40
Task/String-matching/MiniScript/string-matching.mini
Normal file
40
Task/String-matching/MiniScript/string-matching.mini
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
string.startsWith = function(s)
|
||||
return self.len >= s.len and s[:s.len] == s
|
||||
end function
|
||||
|
||||
string.endsWith = function(s)
|
||||
return self.len >= s.len and s[-s.len:] == s
|
||||
end function
|
||||
|
||||
string.findAll = function(s)
|
||||
result = []
|
||||
after = null
|
||||
while true
|
||||
foundPos = self.indexOf(s, after)
|
||||
if foundPos == null then return result
|
||||
result.push foundPos
|
||||
after = foundPos + s.len - 1
|
||||
end while
|
||||
end function
|
||||
|
||||
first = "The brown dog jumped jumped and jumped"
|
||||
second = "jumped"
|
||||
|
||||
firstQ = """" + first + """" // (first string, in quotes)
|
||||
secondQ = """" + second + """"
|
||||
doesOrNot = [" does not ", " does "]
|
||||
|
||||
print firstQ + doesOrNot[first.startsWith(second)] + "start with " + secondQ
|
||||
print
|
||||
|
||||
found = first.findAll(second)
|
||||
if not found then
|
||||
print firstQ + " does not contain " + secondQ + " anywhere"
|
||||
else
|
||||
for pos in found
|
||||
print firstQ + " is found at position " + pos + " in " + secondQ
|
||||
end for
|
||||
end if
|
||||
print
|
||||
|
||||
print firstQ + doesOrNot[first.endsWith(second)] + "end with " + secondQ
|
||||
Loading…
Add table
Add a link
Reference in a new issue