Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
29
Task/String-matching/Phix/string-matching.phix
Normal file
29
Task/String-matching/Phix/string-matching.phix
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
constant word = "the", -- (also try this with "th"/"he")
|
||||
sentence = "the last thing the man said was the"
|
||||
-- sentence = "thelastthingthemansaidwasthe" -- (practically the same results)
|
||||
|
||||
-- A common, but potentially inefficient idiom for checking for a substring at the start is:
|
||||
if match(word,sentence)=1 then
|
||||
?"yes(1)"
|
||||
end if
|
||||
-- A more efficient method is to test the appropriate slice
|
||||
if length(sentence)>=length(word)
|
||||
and sentence[1..length(word)]=word then
|
||||
?"yes(2)"
|
||||
end if
|
||||
-- Which is almost identical to checking for a word at the end
|
||||
if length(sentence)>=length(word)
|
||||
and sentence[-length(word)..-1]=word then
|
||||
?"yes(3)"
|
||||
end if
|
||||
-- Or sometimes you will see this, a tiny bit more efficient:
|
||||
if length(sentence)>=length(word)
|
||||
and match(word,sentence,length(sentence)-length(word)+1) then
|
||||
?"yes(4)"
|
||||
end if
|
||||
-- Finding all occurences is a snap:
|
||||
integer r = match(word,sentence)
|
||||
while r!=0 do
|
||||
?r
|
||||
r = match(word,sentence,r+1)
|
||||
end while
|
||||
Loading…
Add table
Add a link
Reference in a new issue