Count occurrences of a substring: Difference between revisions
Content deleted Content added
→{{header|C sharp}}: added using and class |
→{{header|Euphoria}}: Euphoria example added |
||
Line 154:
Writeln(CountSubstring('ababababab', 'abab'));
end.</lang>
=={{header|Euphoria}}==
<lang euphoria>function countSubstring(sequence s, sequence sub)
integer from,count
count = 0
from = 1
while 1 do
from = match_from(sub,s,from)
if not from then
exit
end if
from += length(sub)
count += 1
end while
return count
end function
? countSubstring("the three truths","th")
? countSubstring("ababababab","abab")</lang>
Output:
<pre>3
2
</pre>
=={{header|Go}}==
|