count-string-matches


/ Published in: Emacs Lisp
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. (defun count-string-matches (strn)
  2. "Return number of matches STRING following the point.
  3. Continues until end of buffer. Also display the count as a message."
  4. (interactive (list (read-string "Enter string: ")))
  5. (save-excursion
  6. (let ((count -1))
  7. (while
  8. (progn
  9. (setq count (1+ count))
  10. (search-forward strn nil t)))
  11. (message "%d matches" count)
  12. count)))

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.