Count occurrences of a substring: Difference between revisions
Content added Content deleted
(→{{header|SNOBOL4}}: Add Ruby.) |
No edit summary |
||
Line 342: | Line 342: | ||
2 |
2 |
||
2</pre> |
2</pre> |
||
=={{header|Liberty BASIC}}== |
|||
<lang lb> |
|||
print countSubstring( "the three truths", "th") |
|||
print countSubstring( "ababababab", "abab") |
|||
end |
|||
function countSubstring( a$, s$) |
|||
c =0 |
|||
la =len( a$) |
|||
ls =len( s$) |
|||
for i =1 to la -ls |
|||
if mid$( a$, i, ls) =s$ then c =c +1: i =i +ls -1 |
|||
next i |
|||
countSubstring =c |
|||
end function |
|||
</lang> |
|||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
<lang lua>function Count_Substring( s1, s2 ) |
<lang lua>function Count_Substring( s1, s2 ) |