Count occurrences of a substring: Difference between revisions
m
→{{header|ALGOL 68}}: Add note about string in string, remove use of formatted transput to make runable with more compilers/interpreters
No edit summary |
m (→{{header|ALGOL 68}}: Add note about string in string, remove use of formatted transput to make runable with more compilers/interpreters) |
||
Line 430:
=={{header|ALGOL 68}}==
Algol68 has no build in function to do this task, hence the next to create a ''count string in string'' routine.<br/>▼
If your Algol 68 compiler/interpreter does not have ''string in string'', there is an implementation on Rosetta Code [[ALGOL_68/prelude#string_in_string|here]].<br>
<syntaxhighlight lang="algol68">PROC count string in string = (STRING needle, haystack)INT: (▼
▲Algol68 has no build in function to do this task, hence the next to create a ''count string in string'' routine.
▲PROC count string in string = (STRING needle, haystack)INT: (
INT start:=LWB haystack, next, out:=0;
FOR count WHILE string in string(needle, next, haystack[start:]) DO
Line 445 ⟶ 441:
);
print((
whole( count string in string("th", "the three truths"), 0 ) # expect 3 #, " ",
whole( count string in string("abab", "ababababab"), 0 ) # expect 2 #, " ",
whole( count string in string("a*b", "abaabba*bbaba*bbab"), 0 ) # expect 2 #, newline
))
{{out}}
<pre>
3 2 2
|