Count occurrences of a substring: Difference between revisions
m
no edit summary
No edit summary |
mNo edit summary |
||
Line 1,548:
<syntaxhighlight lang="emacs lisp">
(defun count-substrings (text substring)
"Count non-overlapping occurrences of SUBSTRING in TEXT."
(with-temp-buffer ; create a temporary buffer, which will be deleted when function finishes
(insert text) ; insert TEXT into the empty buffer
(goto-char (point-min)) ; go to the beginning of the buffer
(how-many substring))) ; count how many occurrences of SUBSTRING
</syntaxhighlight>
{{out}}
|