Jump to content

Count occurrences of a substring: Difference between revisions

(Added Fōrmulæ)
Line 1,472:
scount("na", "banana");
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}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.