Count occurrences of a substring: Difference between revisions
Content deleted Content added
→{{header|Wren}}: Added version using a library method. |
Not a robot (talk | contribs) Add Miranda |
||
Line 1,992:
puts count_substring3("a*b", "abaabba*bbaba*bbab") # ==> 2
</syntaxhighlight>
=={{header|Miranda}}==
<syntaxhighlight lang="miranda">main :: [sys_message]
main = [Stdout (show (countSubstring "the three truths" "th") ++ "\n"),
Stdout (show (countSubstring "ababababab" "abab") ++ "\n")]
countSubstring :: [*]->[*]->num
countSubstring str ss
= 0, if str = []
= 1 + countSubstring (drop len str) ss, if match
= countSubstring (tl str) ss, otherwise
where len = #ss
match = take len str = ss</syntaxhighlight>
{{out}}
<pre>3
2</pre>
=={{header|Nanoquery}}==
|