Count occurrences of a substring: Difference between revisions

Add Draco
(Add Miranda)
(Add Draco)
Line 1,042:
Writeln(CountSubstring('ababababab', 'abab'));
end.</syntaxhighlight>
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc countSubstring(*char string, substring) word:
word count;
*char pos, loc;
count := 0;
while string* /= '\e' do
pos := substring;
loc := string;
while loc* = pos* do
loc := loc + 1;
pos := pos + 1
od;
if pos* = '\e' then
string := loc;
count := count + 1
else
string := string + 1
fi
od;
count
corp
 
proc main() void:
writeln(countSubstring("the three truths", "th"));
writeln(countSubstring("ababababab", "abab"))
corp</syntaxhighlight>
{{out}}
<pre>3
2</pre>
 
=={{header|Dyalect}}==
2,094

edits