Count occurrences of a substring: Difference between revisions
Content deleted Content added
Added AutoHotkey example |
m alphabetized |
||
Line 11:
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 47 ⟶ 38:
3 2 2
</pre>
▲=={{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|C}}==
|