/ Published in: Emacs Lisp

An answer to the 'count-string-matches exercise listed here: http://stackoverflow.com/questions/41522/tips-for-learning-elisp/59589#59589
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
(defun count-string-matches (strn) "Return number of matches STRING following the point. Continues until end of buffer. Also display the count as a message." (interactive (list (read-string "Enter string: "))) (save-excursion (let ((count -1)) (while (progn (setq count (1+ count)) (search-forward strn nil t))) (message "%d matches" count) count)))
URL: http://stackoverflow.com/questions/41522/tips-for-learning-elisp/59589#59589
Comments
