Posted By

bigfaceworm on 08/21/09


String count emacs LISP

Versions (?)


 / Published in: Emacs Lisp


An answer to the 'count-string-matches exercise listed here:

  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)))

Report this snippet  

You need to login to post a comment.