Count occurrences of a substring: Difference between revisions

Added AutoHotkey example
(Added AutoHotkey example)
Line 10:
 
The matching should yield the highest number of non-overlapping matches. In general, this essentially means matching from left-to-right or right-to-left (see proof on talk page).
 
=={{header|AutoHotkey}}==
While it is simple enough to parse the string, AutoHotkey has a rather unconventional method which outperforms this. StringReplace sets the number of replaced strings to ErrorLevel.
<lang AutoHotkey>MsgBox % countSubstring("the three truths","th") ; 3
MsgBox % countSubstring("ababababab","abab") ; 2
 
CountSubstring(fullstring, substring){
StringReplace, junk, fullstring, %substring%, , UseErrorLevel
return errorlevel
}</lang>
 
=={{header|ALGOL 68}}==
Line 37 ⟶ 47:
3 2 2
</pre>
 
=={{header|C}}==
<lang C>#include <stdio.h>