Jump to content

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
(with-temp-buffer ; create a temporary buffer, which will be deleted when function finishes
(insert text)
(insert text) ; insert TEXT into the empty buffer
(goto-char (point-min)) ; go to the beginning of the buffer
(how-many substring)))
(how-many substring))) ; count how many occurrences of SUBSTRING
</syntaxhighlight>
{{out}}
33

edits

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