Count occurrences of a substring: Difference between revisions
Content deleted Content added
m J: reorder arguments to match task requirement |
Added Haskell entry. |
||
Line 150: | Line 150: | ||
2 |
2 |
||
2</pre> |
2</pre> |
||
=={{header|Haskell}}== |
|||
<lang haskell> |
|||
import Data.Text hiding (length) |
|||
-- Return the number of non-overlapping occurrences of sub in str. |
|||
countSubStrs str sub = length $ breakOnAll (pack sub) (pack str) |
|||
main = do |
|||
print $ countSubStrs "the three truths" "th" |
|||
print $ countSubStrs "ababababab" "abab" |
|||
</lang> |
|||
Output: |
|||
<pre> |
|||
3 |
|||
2 |
|||
</pre> |
|||
=={{header|Java}}== |
=={{header|Java}}== |