|
From: | Stephen Berman |
Subject: | Re: count char in string [The Emacs Challenge Competition - round 2, with fallout] |
Date: | Thu, 29 Oct 2020 11:38:09 +0100 |
User-agent: | Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
On Wed, 28 Oct 2020 01:42:13 +0100 Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote: > round 2: > > Very simple: we are looking for a function that returns the number of > occurrences of a char in a string. cl-count? seq-count? seq-reduce? KISS! (defun count-char-in-string (char str) "Return number of occurrences of character CHAR in string STR." (let ((count 0)) (dotimes (i (length str) count) (when (eq char (aref str i)) (setq count (1+ count)))))) Steve Berman
[Prev in Thread] | Current Thread | [Next in Thread] |