Count occurrences of a substring: Difference between revisions
Count occurrences of a substring (view source)
Revision as of 14:17, 21 November 2023
, 7 months agoadd SETL
m (→{{header|Wren}}: Changed to Wren S/H (alternative version)) |
Not a robot (talk | contribs) (add SETL) |
||
Line 3,416:
2
</pre>
=={{header|SETL}}==
<syntaxhighlight lang="setl">program count_overlapping_substrings;
tests := [["the three truths", "th"], ["ababababab", "abab"]];
loop for [s, subs] in tests do
print("'" + subs + "' in '" + s + "': "
+ str countSubs(s, subs));
end loop;
proc countSubs(s, subs);
count := 0;
loop while s(subs) /= om do
s(subs) := "";
count +:= 1;
end loop;
return count;
end proc;
end program;</syntaxhighlight>
{{out}}
<pre>'th' in 'the three truths': 3
'abab' in 'ababababab': 2</pre>
=={{header|SenseTalk}}==
|