RosettaCodeData/Task/String-matching/Pluto/string-matching.pluto
2026-04-30 12:34:36 -04:00

18 lines
524 B
Text

local s = "abracadabra"
local t = "abra"
local u = "ra"
local v = "cad"
print($"'{s}' starts with '{t}' is {s:startswith(t)}")
local indices = {}
local start = 1
while true do
local ix = s:find(u, start, true)
if ix then
indices:insert(ix)
start = ix + #u
if start > #s then break end
else break end
end
local contained = #indices > 0
print($"'{s}' contains '{u}' is {contained} {contained ? $"at indices {indices:concat(", ")}" : ""}")
print($"'{s}' ends with '{v}' is {s:endswith(v)}")