Count occurrences of a substring: Difference between revisions
Content deleted Content added
re-alphabetized languages |
|||
Line 508:
: (countSubstring "ababababab" "abab")
-> 2</pre>
=={{header|PL/I}}==
<lang PL/I>
cnt: procedure options (main);
declare (i, tally) fixed binary;
declare (text, key) character (100) varying;
get edit (text) (L); put skip data (text);
get edit (key) (L); put skip data (key);
tally = 0; i = 1;
do until (i = 0);
i = index(text, key, i);
if i > 0 then do; tally = tally + 1; i = i + length(key); end;
end;
put skip list (tally);
end cnt;
</lang>
Output for the two specified strings is as expected. Output for the
following data:-
<pre>
TEXT='AAAAAAAAAAAAAAA';
KEY='AA';
7
</pre>
=={{header|PureBasic}}==
|