Count occurrences of a substring: Difference between revisions
Content added Content deleted
(Added Fōrmulæ) |
|||
Line 1,472: | Line 1,472: | ||
scount("na", "banana"); |
scount("na", "banana"); |
||
2</lang> |
2</lang> |
||
=={{header|MiniScript}}== |
|||
<lang MiniScript>// Count occurrences of a Substring |
|||
countSubstring = function(string, substring) |
|||
count = 0 |
|||
place = null |
|||
processing = true |
|||
while processing |
|||
found = string.indexOf(substring,place) |
|||
if found == null then |
|||
processing = false |
|||
else |
|||
count = count + 1 |
|||
place = found + substring.len - 1 |
|||
end if |
|||
end while |
|||
return count |
|||
end function |
|||
print countSubstring("the three truths","th") |
|||
print countSubstring("ababababab","abab")</lang> |
|||
{{out}} |
|||
<pre> |
|||
3 |
|||
2 |
|||
</pre> |
|||
=={{header|Mirah}}== |
=={{header|Mirah}}== |