Count occurrences of a substring: Difference between revisions

Content added Content deleted
No edit summary
Line 1,543: Line 1,543:
0
0
0
0
</pre>

=={{header|Emacs Lisp}}==
<syntaxhighlight lang="emacs lisp">
(defun count-substrings (text substring)
(with-temp-buffer
(insert text)
(goto-char (point-min))
(how-many substring)))
</syntaxhighlight>
{{out}}
<pre>
(count-substrings "the three truths" "th")
3

(count-substrings "ababababab" "abab")
2

</pre>
</pre>