Jump to content

Count occurrences of a substring: Difference between revisions

no edit summary
No edit summary
Line 1,543:
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>
 
31

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.