Count occurrences of a substring: Difference between revisions

Content added Content deleted
(Added PicoLisp)
(J)
Line 101: Line 101:
<pre>3
<pre>3
2</pre>
2</pre>

=={{header|J}}==

<lang j>require'strings'
countss=: #@[ %~ #@] - ] #@rplc '';~[</lang>

In other words: find length of original string, replace the string to be counted with the empty string, find the difference in lengths and divide by the length of the string to be counted.

Example use:

<lang j> 'th' countss 'the three truths'
3
'abab' countss 'ababababab'
2</lang>


=={{header|Fortran}}==
=={{header|Fortran}}==