Return to Snippet

Revision: 17057
at August 21, 2009 14:49 by bigfaceworm


Initial Code
(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)))

Initial URL
http://stackoverflow.com/questions/41522/tips-for-learning-elisp/59589#59589

Initial Description
An answer to the 'count-string-matches exercise listed here: http://stackoverflow.com/questions/41522/tips-for-learning-elisp/59589#59589

Initial Title
count-string-matches

Initial Tags


Initial Language
Emacs Lisp