Count occurrences of a substring: Difference between revisions

add SETL
m (→‎{{header|Wren}}: Changed to Wren S/H (alternative version))
(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}}==
2,123

edits